* question regarding gnu-isms
@ 2006-04-27 22:36 Aron Griffis
2006-04-27 23:04 ` Anthony Liguori
2006-04-28 5:09 ` Andi Kleen
0 siblings, 2 replies; 9+ messages in thread
From: Aron Griffis @ 2006-04-27 22:36 UTC (permalink / raw)
To: xen-devel
I understand most of the gcc extensions that I find in xen, for
example ({...}) in a #define. However I've come across a couple that
I'm not familiar with. Does somebody mind explaining the point of
these?
from linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h:
#define __pte_ma(_x) ((pte_t) {(_x)})
What's the point of the braces here?
same file:
#define xen_create_contiguous_region(vstart, order, address_bits) ({0;})
This looks like the usual ({...}) construction but seems
pointless. The nearest explanation I could gather for this
applies only to C++... surely I'm missing something. :-)
Thanks,
Aron
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: question regarding gnu-isms
2006-04-27 22:36 question regarding gnu-isms Aron Griffis
@ 2006-04-27 23:04 ` Anthony Liguori
2006-04-27 23:08 ` Mark Williamson
2006-04-27 23:16 ` Aron Griffis
2006-04-28 5:09 ` Andi Kleen
1 sibling, 2 replies; 9+ messages in thread
From: Anthony Liguori @ 2006-04-27 23:04 UTC (permalink / raw)
To: xen-devel
Aron Griffis wrote:
> I understand most of the gcc extensions that I find in xen, for
> example ({...}) in a #define. However I've come across a couple that
> I'm not familiar with. Does somebody mind explaining the point of
> these?
>
> from linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h:
>
> #define __pte_ma(_x) ((pte_t) {(_x)})
>
This is structure initialization assignment. pte_t is a struct. It can
be initialized like:
pte_t pte = {0};
If you want to assign to it with a similar structure, you cannot do:
pte_t pte = {0};
pte = {3};
The GNU extension allows you to do this by doing:
pte_t pte = {0};
pte = (pte_t){3};
> What's the point of the braces here?
>
> same file:
>
> #define xen_create_contiguous_region(vstart, order, address_bits) ({0;})
>
This is a really common one that lets you make statements into
expressions. Say you wanted to implement a min function over int's as a
macro, to do it properly, you have to do something like:
#define min(a, b) {int lhs = a; int rhs = b; return (lhs < rhs) ? lhs :
rhs; }
But clearly you cannot use return for this (and you cannot avoid making
a statement here). The GNU ({}) syntax allows you to have statements
within an expression and the value of the very last statement in the
block becomes the value of the expression. The above could be written:
#define min(a, b) ({int lhs = a; int rhs = b; (lhs < rhs) ? lhs : rhs;})
All of these are documented in the GCC Info page (see the section on C
Extensions).
Regards,
Anthony Liguori
> This looks like the usual ({...}) construction but seems
> pointless. The nearest explanation I could gather for this
> applies only to C++... surely I'm missing something. :-)
>
> Thanks,
> Aron
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: question regarding gnu-isms
2006-04-27 23:04 ` Anthony Liguori
@ 2006-04-27 23:08 ` Mark Williamson
2006-04-27 23:41 ` Anthony Liguori
2006-04-27 23:16 ` Aron Griffis
1 sibling, 1 reply; 9+ messages in thread
From: Mark Williamson @ 2006-04-27 23:08 UTC (permalink / raw)
To: xen-devel; +Cc: aron
OK, now I'm curious too...
> > same file:
> >
> > #define xen_create_contiguous_region(vstart, order, address_bits)
> > ({0;})
>
<snip parts of explanation>
> But clearly you cannot use return for this (and you cannot avoid making
> a statement here). The GNU ({}) syntax allows you to have statements
> within an expression and the value of the very last statement in the
> block becomes the value of the expression. The above could be written:
But why do that, if you just wanted to return a constant? why not
#define xen_create_contiguous_region(vstart, order, address_bits) 0
for instance?
Cheers,
Mark
>
> #define min(a, b) ({int lhs = a; int rhs = b; (lhs < rhs) ? lhs : rhs;})
>
> All of these are documented in the GCC Info page (see the section on C
> Extensions).
>
> Regards,
>
> Anthony Liguori
>
> > This looks like the usual ({...}) construction but seems
> > pointless. The nearest explanation I could gather for this
> > applies only to C++... surely I'm missing something. :-)
> >
> > Thanks,
> > Aron
> >
> > _______________________________________________
> > Xen-devel mailing list
> > Xen-devel@lists.xensource.com
> > http://lists.xensource.com/xen-devel
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
--
Dave: Just a question. What use is a unicyle with no seat? And no pedals!
Mark: To answer a question with a question: What use is a skateboard?
Dave: Skateboards have wheels.
Mark: My wheel has a wheel!
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: question regarding gnu-isms
2006-04-27 23:08 ` Mark Williamson
@ 2006-04-27 23:41 ` Anthony Liguori
2006-04-27 23:41 ` Mark Williamson
0 siblings, 1 reply; 9+ messages in thread
From: Anthony Liguori @ 2006-04-27 23:41 UTC (permalink / raw)
To: Mark Williamson; +Cc: aron, xen-devel
Mark Williamson wrote:
> OK, now I'm curious too...
>
>
>>> same file:
>>>
>>> #define xen_create_contiguous_region(vstart, order, address_bits)
>>> ({0;})
>>>
> <snip parts of explanation>
>
>> But clearly you cannot use return for this (and you cannot avoid making
>> a statement here). The GNU ({}) syntax allows you to have statements
>> within an expression and the value of the very last statement in the
>> block becomes the value of the expression. The above could be written:
>>
>
> But why do that, if you just wanted to return a constant? why not
>
> #define xen_create_contiguous_region(vstart, order, address_bits) 0
>
> for instance?
>
I thought the same exact thing myself. Of course, I can't find it in my
tree (xen_create_contiguous_region is a function) so perhaps someone has
already fixed it.
Regards,
Anthony Liguori
> Cheers,
> Mark
>
>
>> #define min(a, b) ({int lhs = a; int rhs = b; (lhs < rhs) ? lhs : rhs;})
>>
>> All of these are documented in the GCC Info page (see the section on C
>> Extensions).
>>
>> Regards,
>>
>> Anthony Liguori
>>
>>
>>> This looks like the usual ({...}) construction but seems
>>> pointless. The nearest explanation I could gather for this
>>> applies only to C++... surely I'm missing something. :-)
>>>
>>> Thanks,
>>> Aron
>>>
>>> _______________________________________________
>>> Xen-devel mailing list
>>> Xen-devel@lists.xensource.com
>>> http://lists.xensource.com/xen-devel
>>>
>> _______________________________________________
>> Xen-devel mailing list
>> Xen-devel@lists.xensource.com
>> http://lists.xensource.com/xen-devel
>>
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: question regarding gnu-isms
2006-04-27 23:41 ` Anthony Liguori
@ 2006-04-27 23:41 ` Mark Williamson
0 siblings, 0 replies; 9+ messages in thread
From: Mark Williamson @ 2006-04-27 23:41 UTC (permalink / raw)
To: Anthony Liguori; +Cc: aron, xen-devel
> I thought the same exact thing myself. Of course, I can't find it in my
> tree (xen_create_contiguous_region is a function) so perhaps someone has
> already fixed it.
Maybe the "0" is a macro </joking>
:-)
Cheers,
Mark
> Regards,
>
> Anthony Liguori
>
> > Cheers,
> > Mark
> >
> >> #define min(a, b) ({int lhs = a; int rhs = b; (lhs < rhs) ? lhs : rhs;})
> >>
> >> All of these are documented in the GCC Info page (see the section on C
> >> Extensions).
> >>
> >> Regards,
> >>
> >> Anthony Liguori
> >>
> >>> This looks like the usual ({...}) construction but seems
> >>> pointless. The nearest explanation I could gather for this
> >>> applies only to C++... surely I'm missing something. :-)
> >>>
> >>> Thanks,
> >>> Aron
> >>>
> >>> _______________________________________________
> >>> Xen-devel mailing list
> >>> Xen-devel@lists.xensource.com
> >>> http://lists.xensource.com/xen-devel
> >>
> >> _______________________________________________
> >> Xen-devel mailing list
> >> Xen-devel@lists.xensource.com
> >> http://lists.xensource.com/xen-devel
--
Dave: Just a question. What use is a unicyle with no seat? And no pedals!
Mark: To answer a question with a question: What use is a skateboard?
Dave: Skateboards have wheels.
Mark: My wheel has a wheel!
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: question regarding gnu-isms
2006-04-27 23:04 ` Anthony Liguori
2006-04-27 23:08 ` Mark Williamson
@ 2006-04-27 23:16 ` Aron Griffis
2006-04-27 23:44 ` Anthony Liguori
1 sibling, 1 reply; 9+ messages in thread
From: Aron Griffis @ 2006-04-27 23:16 UTC (permalink / raw)
To: Anthony Liguori; +Cc: xen-devel
Hi Anthony,
Thanks for the explanation of the struct initialization. Regarding
the second one, though...
Anthony Liguori wrote: [Thu Apr 27 2006, 07:04:01PM EDT]
> Aron Griffis wrote:
> > #define xen_create_contiguous_region(vstart, order, address_bits)
> > ({0;})
>
> This is a really common one that lets you make statements into
> expressions.
...
>
> #define min(a, b) ({int lhs = a; int rhs = b; (lhs < rhs) ? lhs : rhs;})
That makes sense for the example you gave, but how does it apply to
the definition in question? Is there any difference between ({0;})
and (0) or even 0?
> All of these are documented in the GCC Info page (see the section on
> C Extensions).
:-) I read that before posting, so I was familiar with the purpose of
enclosing compound statements in expressions. But I'll reread in case
there's something I missed regarding the interpretation of ({0;})
Regards,
Aron
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: question regarding gnu-isms
2006-04-27 23:16 ` Aron Griffis
@ 2006-04-27 23:44 ` Anthony Liguori
2006-04-29 1:44 ` Aron Griffis
0 siblings, 1 reply; 9+ messages in thread
From: Anthony Liguori @ 2006-04-27 23:44 UTC (permalink / raw)
To: Anthony Liguori, xen-devel
Aron Griffis wrote:
> Hi Anthony,
>
> Thanks for the explanation of the struct initialization. Regarding
> the second one, though...
>
> Anthony Liguori wrote: [Thu Apr 27 2006, 07:04:01PM EDT]
>
>> Aron Griffis wrote:
>>
>>> #define xen_create_contiguous_region(vstart, order, address_bits)
>>> ({0;})
>>>
>> This is a really common one that lets you make statements into
>> expressions.
>>
> ...
>
>> #define min(a, b) ({int lhs = a; int rhs = b; (lhs < rhs) ? lhs : rhs;})
>>
>
> That makes sense for the example you gave, but how does it apply to
> the definition in question? Is there any difference between ({0;})
> and (0) or even 0?
>
Can you point me to where you saw this (and in what version of Xen)?
There is no difference between (0) and 0 of course. I don't *think*
there's a difference between ({0;}) and (0) but of course I've seen
stranger things before. My guess is that it started it's life as a more
complex set of statements and overtime was reduced to just that.
Regards,
Anthony Liguori
>> All of these are documented in the GCC Info page (see the section on
>> C Extensions).
>>
>
> :-) I read that before posting, so I was familiar with the purpose of
> enclosing compound statements in expressions. But I'll reread in case
> there's something I missed regarding the interpretation of ({0;})
>
> Regards,
> Aron
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: question regarding gnu-isms
2006-04-27 23:44 ` Anthony Liguori
@ 2006-04-29 1:44 ` Aron Griffis
0 siblings, 0 replies; 9+ messages in thread
From: Aron Griffis @ 2006-04-29 1:44 UTC (permalink / raw)
To: xen-devel
Anthony Liguori wrote: [Thu Apr 27 2006, 07:44:37PM EDT]
> Can you point me to where you saw this (and in what version of Xen)?
xen-unstable, linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h
> There is no difference between (0) and 0 of course. I don't *think*
> there's a difference between ({0;}) and (0) but of course I've seen
> stranger things before. My guess is that it started it's life as
> a more complex set of statements and overtime was reduced to just
> that.
Thanks. I was suspcious that might be the case, but didn't want to
assume... :-)
Regards,
Aron
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: question regarding gnu-isms
2006-04-27 22:36 question regarding gnu-isms Aron Griffis
2006-04-27 23:04 ` Anthony Liguori
@ 2006-04-28 5:09 ` Andi Kleen
1 sibling, 0 replies; 9+ messages in thread
From: Andi Kleen @ 2006-04-28 5:09 UTC (permalink / raw)
To: Aron Griffis; +Cc: xen-devel
Aron Griffis <aron@hp.com> writes:
> I understand most of the gcc extensions that I find in xen, for
> example ({...}) in a #define. However I've come across a couple that
> I'm not familiar with. Does somebody mind explaining the point of
> these?
>
> from linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h:
>
> #define __pte_ma(_x) ((pte_t) {(_x)})
This isn't a GNUism anymore, it's C99.
-Andi
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2006-04-29 1:44 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-27 22:36 question regarding gnu-isms Aron Griffis
2006-04-27 23:04 ` Anthony Liguori
2006-04-27 23:08 ` Mark Williamson
2006-04-27 23:41 ` Anthony Liguori
2006-04-27 23:41 ` Mark Williamson
2006-04-27 23:16 ` Aron Griffis
2006-04-27 23:44 ` Anthony Liguori
2006-04-29 1:44 ` Aron Griffis
2006-04-28 5:09 ` Andi Kleen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.