I wrote this simple assembly code, ran it and looked at the memory location using GDB:It's adding 5 to 6 directly in memory and according to GDB it worked. So this is performing math operations directly in memory instead of CPU registers.
According to the C++ standard, when forward-declaring a template type with default template parameters, each of them can appear in one declaration only. For example:
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.