bool to int conversion

int x = 4<5; Completely portable. Standard conformant. bool to int conversion is implicit! §4.7/4 from the C++ 11 or 14 Standard, §7.8/4 from the C++ 17 Standard, §7.3.9/2 from the 20 Standard says (Integral Conversion) If the source type is bool, the value false is converted to zero and the value true is converted … Read more

Standard alternative to GCC’s ##__VA_ARGS__ trick?

There is an argument counting trick that you can use. Here is one standard-compliant way to implement the second BAR() example in jwd’s question: #include <stdio.h> #define BAR(…) printf(FIRST(__VA_ARGS__) “\n” REST(__VA_ARGS__)) /* expands to the first argument */ #define FIRST(…) FIRST_HELPER(__VA_ARGS__, throwaway) #define FIRST_HELPER(first, …) first /* * if there’s only one argument, expands to … Read more

Realistic usage of the C99 ‘restrict’ keyword?

restrict says that the pointer is the only thing that accesses the underlying object. It eliminates the potential for pointer aliasing, enabling better optimization by the compiler. For instance, suppose I have a machine with specialized instructions that can multiply vectors of numbers in memory, and I have the following code: void MultiplyArrays(int* dest, int* … Read more

What is the behavior of integer division?

Will result always be the floor of the division? What is the defined behavior? Not quite. It rounds toward 0, rather than flooring. 6.5.5 Multiplicative operators 6 When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded.88) If the quotient a/b is representable, the expression (a/b)*b … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)