bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: glthread_cond_timedwait errors on C99 code


From: Bruno Haible
Subject: Re: glthread_cond_timedwait errors on C99 code
Date: Sat, 30 Sep 2017 16:31:22 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-93-generic; KDE/5.18.0; x86_64; ; )

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.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]