Problem Code: Inline
Ok, first post, I know I'm not allowed to ask for someone to do my homework for me but I've looked everywhere for a possible solution to this peice of problem code and I cant even find a complier that replicates the error let alone a mention of what I should be looking for:
It's an inline int Max(a, b) function thats given 10, and 0 as
The question says that sometimes this code will return 0, I cant find a complier that does that.
typedef unsigned short Word;
Max( int n, int m)
return n>m ? n : m;
Word w1=40000,w2 = 0;
printf( “%d\n”, Max( w1, w2) );
Any help just with what errors i should be looking for would be greatly appricated.
My only guess is that it's something to do with the usage of short, do some compilers not recognise the unsigned property? If that were true the 40000 value would be greater than the positive limit for a short and the program would return 0...or error.
It's not guaranteed that 'int' will be thirty-two bits wide. Then the arguments to Max could be, on some systems, 16 bit signed integers, making Max receive w1 as a negative value (since it's greater than 2^31 - 1).
Genius. Thanks very much :D
I found where it returns zero! :p
Originally Posted by CodingFleet
Picking lint: should say (since it's greater than 2^15- 1).
Originally Posted by Rashakil Fol
So a compiler with 16-bit ints will see 40000 as a negative number because the function Max isn't using unsigned. A good compiler with warnings enabled should also warn about mixing signed and unsigned.
If you want to try out such a compiler, see if you can find really old versions of Turbo C.