| 
    
 [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] question regarding gnu-isms
 Aron Griffis wrote: 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};
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 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel 
 
 
  | 
  
![]()  | 
            
         Lists.xenproject.org is hosted with RackSpace, monitoring our  |