On 02/06/2014 01:14 PM, Philip Herron wrote:
I am trying to understand what way i could compile this in GCC can you
do the following in GENERIC make a nested function decl kind of like a
closure not quite sure what to do here.
It's just a statement expression. The C front end supports them, so
this might give you some idea how to implement them.
void main (void) {
const char * item = "test";
const double price = ({
double ret_tmp;
if (item == "salad") {
ret_tmp = 3.50;
}
else if (item == "muffin") {
ret_tmp = 2.25;
}
else {
ret_tmp = 2.00;
}
ret_tmp;
});
}
To compile general closures, you have to apply a transformation called
closure conversion. GCC's nested functions only provide downward
closures, and require an executable stack for trampolines on most
architectures, which many systems do not support.
--
Florian Weimer / Red Hat Product Security Team