4 ms·
This is expecting a pointer. A NULL sentinel attribute should be set to catch this (if you are using GCC). And GCC does catch this exact error. void blah(int a
by audidude 15y ago
This is expecting a pointer. A NULL sentinel attribute should be set to catch this (if you are using GCC). And GCC does catch this exact error.
void blah(int a, ...) __attribute__((sentinel));
blah(123, 0); will cause gcc to spew "warning: missing sentinel in function call" while blah(123, NULL); will not.
Additionally, one should remember types are important in va_arg functions. For example, passing in 0 when a parameter expects a int64_t, is the same error. It is useful to know that float is promoted to double in va_arg functions and int8_t, int16_t, and bool are promoted to int32_t.
This often causes problems with people new to C using GObject's g_object_set() and g_object_get() functions.
- malkia 15y agoThanks, that was very useful.