c++ - Newbie here: Different results on PC and MAC. Why? -


i trying learn basics of c/c++ right now. going through course on lynda.com

my questions deals sequence of code chapter 4 "macro caveats course c/c++ essential training". have followed setup procedures xcode , eclipse setup correctly on mac , eclipse on pc. when run code on mac , pc different results. trying understand why happening , can same result on both.

here code:

// working.c bill weinman <http://bw.org/>  #include <stdio.h> #define max(a, b) ( (a) > (b) ? (a) : (b) )  int increment() {     static int = 42;     += 5;     printf("increment returns %d\n", i);     return i; }  int main( int argc, char ** argv ) {     int x = 50;     printf("max of %d , %d %d\n", x, increment(), max(x, increment()));     printf("max of %d , %d %d\n", x, increment(), max(x, increment()));     return 0; } 

on pc result:

increment returns 47 increment returns 52 max of 50 , 52 50 increment returns 57 increment returns 62 increment returns 67 max of 50 , 67 62 

on mac (both xcode , eclipse) result:

increment returns 47 increment returns 52 increment returns 57 max of 50 , 47 57 increment returns 62 increment returns 67 increment returns 72 max of 50 , 62 72 

why happening , can make sure results same?

you have unspecified results here.

order of evaluation within printf() not defined. once have multiple increment() calls within same printf never know once gets executed first , how evaluated.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -