This post is mostly a quick reference to keep me from shooting myself in the foot again.
Comma operator
C has a binary operator that evalutes both its argument and discards the result of the first expression.
int main() {
int a = 0;
int b = 1;
int c = (a, b);
printf("c = %d\n", c); // Prints 1
}Works with function calls too:
void trippy_function() {
/* Do something */
}
int main() {
int a = 100;
printf("value = %d\n", (trippy_function(), a)); // Prints 100
}And, works with more than two values:
void foo() {}
void bar() {}
int main() {
printf("c = %d\n", (foo(), bar(), 100)); // Prints 100
}typedef-ing a pointer (C++)
const modifier on a typedef-ed pointer is different than
typedef-ed const pointer.
typedef int* ptr; // void pointer
typedef const int* cptr; // pointer to constant int
int main() {
cout << boolalpha << is_same<const int*, const ptr>() << "\n"; // false
cout << boolalpha << is_same<const int*, cptr>() << "\n"; // true
}const int* is a pointer to a constant int, while const ptr is a constant pointer to an int.