Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C

Name: Anonymous 2009-10-20 17:13

Hey!

Is there a shortcut for this "pattern":
c = (a -b);
if (c != 0) return c;
c = (d-c);
if (c != 0); return c;
//...



I don't quite see how I can avoid storing c, because it matters if it's <0 or >0... or does it get optimized away anyway?

--

qsort, bsearch, and so on take a function whose arguments need to be "const void *p". Is there a way to cast them into the right type right in the function definition, without needing to either introduce two new variables, or cast them every time they're used?

Thanks /prog/!

Name: EXPERT PROGRAMMER 2009-10-21 3:31


#define RETURN_IF_NZ( expr )           \
        ({ typeof(expr) _res = (expr); \
           if( _res != 0 )             \
              return _res;             \
         })

/* ...  */

RETURN_IF_NZ( f1(a1) - f2(a2) );
RETURN_IF_NZ( f3(a3) - f4(a4) );
RETURN_IF_NZ( f5(a5) - f6(a6) );


GCC QUALITY

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List