On Samstag, 30. September 2017 16:31:22 CEST Bruno Haible wrote: > Tim Rühsen wrote: > > The line > > > > return glthread_cond_timedwait(&cond->cond, &mutex->mutex, &(struct > > > > timespec){ .tv_sec = ms / 1000, .tv_nsec = (ms % 1000) * 1000000 }); > > > > errors with > > > > thread.c:155:136: error: macro "glthread_cond_timedwait" passed 4 > > arguments, but takes just 3 > > > > return glthread_cond_timedwait(&cond->cond, &mutex->mutex, &(struct > > > > timespec){ .tv_sec = ms / 1000, .tv_nsec = (ms % 1000) * 1000000 }); > > That's because glthread_cond_timedwait is a macro, and you are passing it > the arguments > &cond->cond > &mutex->mutex > &(struct timespec){ .tv_sec = ms / 1000 > .tv_nsec = (ms % 1000) * 1000000 } > > > This is with gcc 7.2.0 in C99 (default) mode. Is it the preprocessor, my > > code or the macro broken ? Or a general C99 flaw ? > > BTW, putting brackets () around the last argument makes it compile. > > It's a general C flaw: The C preprocessor considers only opening > parentheses, closing parentheses, and commas as syntactically relevant. > Everything else are "other tokens". A consequence of this is that you need > to use extra parentheses when passing comma-expressions or struct > initializers to macros.
Thanks for your explanation, Bruno :-) Regards, Tim
signature.asc
Description: This is a digitally signed message part.