Skip to content

Instantly share code, notes, and snippets.

@gunchev
Created January 20, 2021 19:52
Show Gist options
  • Save gunchev/32ae71ca72647222be98b327092fd71f to your computer and use it in GitHub Desktop.
Save gunchev/32ae71ca72647222be98b327092fd71f to your computer and use it in GitHub Desktop.
/*usr/bin/true; A="$(readlink -f -- "$0")"; function x { rm "$A.bin"; }; trap x EXIT; g++ --std=c++14 -Wall -Wno-unused-label "$A" -o "$A.bin"; "$A.bin"; E=$?; exit $E; # */
// This can be used as script - chmod +x this.cpp; ./this.cpp
#include <cstdio>
constexpr const size_t strlen_const(const char* s) {
return '\0' == *s ? 0 : strlen_const(s + 1) + 1;
}
int main() {
https://stackoverflow.com/a/25891133/1136400
constexpr static const char* str1 = "123";
constexpr size_t len1 = strlen_const(str1);
printf("strlen(\"%s\") = %zu.\n", str1, len1);
constexpr static const char* str2 = "123456789012345678901234567890123";
constexpr size_t len2 = strlen_const(str2);
printf("strlen(\"%s\") = %zu.\n", str2, len2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment