From: Anthony Liguori <aliguori@us.ibm.com>
To: xen-devel@lists.xensource.com
Subject: Re: question regarding gnu-isms
Date: Thu, 27 Apr 2006 18:04:01 -0500 [thread overview]
Message-ID: <44514DE1.3000201@us.ibm.com> (raw)
In-Reply-To: <20060427223641.GG3572@vino.zko.hp.com>
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
>
next prev parent reply other threads:[~2006-04-27 23:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-27 22:36 question regarding gnu-isms Aron Griffis
2006-04-27 23:04 ` Anthony Liguori [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=44514DE1.3000201@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.