Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: curly braces inside for loop parameter |
| Date | 2015-05-17 12:28 -0700 |
| Organization | None to speak of |
| Message-ID | <87d21z9f6u.fsf@kst-u.example.com> (permalink) |
| References | <a6f4eb2e-e20e-41da-b007-db42b48b0421@googlegroups.com> |
Daniel Doron <danielmeirdoron@gmail.com> writes:
> I am working on some stuff involving hlists in kernel. I have seen
> this in lists.h:
>
> #define hlist_for_each_entry(tpos, pos, head, member) \
> for (pos = (head)->first; \
> pos && \
> ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
> pos = pos->next)
>
>
> I have never encountered this syntax in C before, I am referring to
> the curly braces and dangling "1" inside the for loop second
> parameter. Can someone explain this?
This:
( { ... } )
is called a "statement expression". It doesn't exist in standard
C, so any code that uses it is not portable. It's a gcc-specific
extension (presumably also implemented by other compilers that
emulate gcc).
The feature is documented here:
https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Statement-Exprs.html
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
curly braces inside for loop parameter Daniel Doron <danielmeirdoron@gmail.com> - 2015-05-17 06:56 -0700
Re: curly braces inside for loop parameter asetofsymbols@gmail.com - 2015-05-17 07:49 -0700
Re: curly braces inside for loop parameter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-17 15:52 +0100
Re: curly braces inside for loop parameter Bartc <bc@freeuk.com> - 2015-05-17 16:01 +0100
Re: curly braces inside for loop parameter David Kleinecke <dkleinecke@gmail.com> - 2015-05-17 09:14 -0700
Re: curly braces inside for loop parameter Bartc <bc@freeuk.com> - 2015-05-17 17:43 +0100
Re: curly braces inside for loop parameter raltbos@xs4all.nl (Richard Bos) - 2015-05-23 10:33 +0000
Re: curly braces inside for loop parameter Keith Thompson <kst-u@mib.org> - 2015-05-17 12:28 -0700
curly braces inside for loop parameter Chad <cdalten@gmail.com> - 2015-05-17 13:53 -0700
Re: curly braces inside for loop parameter gazelle@shell.xmission.com (Kenny McCormack) - 2015-05-17 21:36 +0000
csiph-web