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.
Consider the following codewhich yieldsSo it basically looks as if the externally defined constructor perfectly forwards the value category of its argument while the inline-defined constructor does not.
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.
I asked myself whether the this pointer could be overused since I usually use it every single time I refer to a member variable or function. I wondered if it could have performance impact since there must be a pointer which needs to be dereferenced every time. So I wrote...
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
the function above is unsafe clearly. Following is another version. I have some questions: the compiler(gcc), in the second version, doesn't give me any warning. Is it safe? I just think that compiler(or something?) will create a temporary variable to hold the return of expression std::to_string(vlu) + "something". So the...
I have a class with a deleted move constructor and when I try to call std::vector::push_back() in MSVC (v.15.8.7 Visual C++ 2017) I get an error saying that I am trying to access the deleted move constructor. If however I define the move constructor, the code compiles, but the move...
Here is my code: If I compile this with O0 option, g++ -O0 main.cpp -o main, the result is 1. If I compile with O2 option, g++ -O2 main.cpp -o main, this will give a result of 0.