Jack said:
On 16 Nov 2006 18:41:39 -0800, "(e-mail address removed)" <
[email protected]>
wrote in comp.lang.c: [...]
#include <stdio.h>
#include <limits.h>
typedef int Man;
void typedef_func1(void)
{
Man i;
i = INT_MAX;
printf("INT_MAX: %d\n", i);
}
#ifdef Man
#undef Man
typedef char Man;
Did you compile this? What diagnostic did your compiler emit when it
processed the line above.
Actually, no diagnostic is required, since "#ifdef Man" is false.
Absolutely, positively, for sure you did not compile this with a C
compiler.
Either you did not compile it at all, or you compiled it with
something that does not claim to be a C compiler.
It should "work" just fine. However, what it does is not what
whua113 thinks it does. Because the "#ifdef Man" is false, the
supposed redefinition of Man never takes place. Man is still a
typedef for int. Since an int can contain CHAR_MAX, the output
"looks right".
Change the printfs to:
printf("INT_MAX: %d, sizeof(Man) is %d\n", (int)c,(int)sizeof(Man));
and
printf("CHAR_MAX: %d, sizeof(Man) is %d\n", (int)c,(int)sizeof(Man));
and you will see that sizeof(Man) is the same in both. (On my
system, they are both 4. Since sizeof char is defined as "1",
you know that Man cannot be a typedef of char.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody |
www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net |
www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:
[email protected]>