# Problem Code: Inline

• 07-21-2007
CodingFleet
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

Code:

```#include <stdio.h> typedef unsigned short Word; inline int Max( int n, int m) {     return n>m ? n : m; } Word w1=40000,w2 = 0; int main() {     printf( “%d\n”, Max( w1, w2) );     return 0; }```
The question says that sometimes this code will return 0, I cant find a complier that does that.

Any help just with what errors i should be looking for would be greatly appricated.
• 07-21-2007
CodingFleet
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.
• 07-21-2007
Rashakil Fol
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).
• 07-21-2007
CodingFleet
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOh.

Genius. Thanks very much :D
• 07-21-2007
iMalc
Quote:

Originally Posted by CodingFleet
Code:

`    return 0;`
The question says that sometimes this code will return 0, I cant find a complier that does that.

I found where it returns zero! :p
• 07-24-2007
matsp
Quote:

Originally Posted by Rashakil Fol
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).

Picking lint: should say (since it's greater than 2^15- 1).

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.

--
Mats
• 07-25-2007
CornedBee
If you want to try out such a compiler, see if you can find really old versions of Turbo C.