= C++ • http://yosefk.com/c++fqa/ • Arguments why is C not compatible with C++? • C allows sophisticated struct initialization like { .member[0] = "hello" }, C++ does not • The semantics of a void argument list: `fn()` means “variadic” in C and “no arguments“ in C++. `fn(void)` means “no arguments” in both == G++ call g++ -Wall -Wextra -Wnull-dereference -Wsuggest-attribute=const -flto -fanalyzer -Wfloat-equal -Wduplicated-branches -Wduplicated-cond -fsanitize=address -Wlogical-op -Wrestrict -Wuseless-cast -Wdouble-promotion -Wshadow -Wformat=2 -Wold-style-cast “g++” == “gcc -xc++ -lstdc++ -shared-libgcc” == Supported standards by GCC w/o GNU ext w/ GNU ext C++23 -std=c++2b -std=gnu++2b C++20 -std=c++20 -std=gnu++2b C++17 -std=c++17 -std=gnu++17 C++14 -std=c++14 -std=gnu++14 C++11 -std=c++11 -std=gnu++11 C++98 -std=c++98 -std=gnu++98 == C uniform implementation #ifdef __cplusplus extern "C" { #endif … declarations … #ifdef __cplusplus } #endif == Constructor syntaxes A a1 = A_factory_func(); // calls copy ctor A a1(A_factory_func()); // calls copy ctor A a1; // calls default ctor a1 = A_factory_func(); // calls operator = == Initialization syntax A x(3); // direct initialization (since C++98) A x = A(3); // copy initialization (can be optimized into direct initialization if LHS and RHS have same type since C++17, disabled with -fno-elide-constructors) == curly brace syntax https://stackoverflow.com/q/9976927 std::complex c = {3,4}; auto e = std::complex{3,4}; == best practice via https://stackoverflow.com/a/9977536 exact value provided → assignment (=) stored-in-object values → curly brace syntax else e.g. description of object → parenthesis syntax pitfall example: string(50, 'x') vs. string{50, 'x'} == SFINAE "substitution failure is not an error" 1. try to replace the type argument with a real type and compile. 2. Fails? Then don't consider it as an error, but try to find overloaded functions such that it still compiles Since C++03 more and more cases are not errors anymore but cases that can be caught Seems to enable many patterns where compile-time checks about the provided type argument are done and it compiles iff it satisfies the conditions == Grand C++ error explosion 2024 via https://tgceec.tumblr.com/post/74534916370/results-of-the-grand-c-error-explosion • templateclass L{Loperator->()};Li=i-> • struct x struct zv