[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: glthread_cond_timedwait errors on C99 code
From: |
Tim Rühsen |
Subject: |
Re: glthread_cond_timedwait errors on C99 code |
Date: |
Sat, 30 Sep 2017 18:58:51 +0200 |
User-agent: |
KMail/5.2.3 (Linux/4.12.0-2-amd64; KDE/5.37.0; x86_64; ; ) |
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.