I have this test program, using a #define constant:When compiled with “Apple LLVM version 10.0.0 (clang-1000.11.45.5)”, I get an executable of 8432 bytes. Here is the assembly listing:
On https://en.cppreference.com/w/cpp/utility/hash it says that since C++17Each standard library header that declares the template std::hash provides enabled specializations of std::hash for std::nullptr_t and all cv-unqualified arithmetic types (including any extended integer types), all enumeration types, and all pointer types.
Why is a constexpr function no evaluated at compile time but in runtime in the return statement of main function?
David Hollman recently tweeted the following example (which I've slightly reduced):You can examine the layout in clang on godbolt and see that the reason the size changed is that in FooBefore, the member value is placed at offset 16 (maintaining a full alignment of 8 from FooBeforeBase) whereas in FooAfter,...
According to this reference manualFor every std::atomic (whether or not specialized), std::atomic::value_type is X.
I recently stumbled on a weird code construct that lead the C compilers to a strange state. I would like to have an explanation why it occurs.
When applied to a function, the [[nodiscard]] attribute encourages the compiler to issue a warning if it is used in a discarded expression other than a cast to void. Example:
I came across a situation where it would be useful to have unnecessary calls to realloc being optimized out. However, it seems like neither clang nor gcc do such a thing (godbolt). - Although I see optimizations being made with multiple calls to malloc.
Reading the fine print of the -I switch in GCC, I'm rather shocked to find that using it on the command line overrides system includes. From the preprocessor docs
I use the __DATE__ macro for getting a compile-time year:The Clang Code Model in QtCreator throws a -Wdate-time warning for using the __DATE__ macro.