Philip Herron 2014-02-06 16:14:
Hey all In rust you can do the following: fn main () { let item = "test"; let price = if item == "salad" { 3.50 } else if item == "muffin" { 2.25 } else { 2.00 }; } 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. I've been using bison to parse rust so far but its getting really painful now for this kind of syntax i am hoping a glr parser might do it (avoiding being a real man and writing a parser by hand untill i have more stuff working). void main (void) { const char * item = "test"; double priceClousure (void) { double ret_tmp; if (item == "salad") { ret_tmp = 3.50; } else if (item == "muffin") { ret_tmp = 2.25; } else { ret_tmp = 2.00; } return ret_tmp; } const double price = priceClousure (); } Thanks --Phil
Hi, Ternary operator? http://en.wikipedia.org/wiki/%3F:#C -- Regards, niXman ___________________________________________________ Dual-target(32 & 64-bit) MinGW-W64 compilers for 32 and 64-bit Windows: http://sourceforge.net/projects/mingw-w64/ ___________________________________________________ Another online IDE: http://liveworkspace.org/