typedef vs #define
Henry Spencer
henry at utzoo.uucp
Sun Feb 25 10:44:33 AEST 1990
In article <8430 at cbnewsh.ATT.COM> em at cbnewsh.ATT.COM (edward.man) writes:
> typedef short FLAGS
> #define FLAGS short
>
>If I had two identical pieces of code, one used the "typedef" and
>ther other "#define" as defined above, would there be any difference
>in the compiled code? Does the C compiler handle the two differently?
The #define is handled by the preprocessor, while the typedef is handled
by the compiler proper. (Actually, a less implementation-dependent way
of stating this is that the #define is handled in ANSI C translation
phase 4 while typedef is handled in phase 7.) In this particular case,
it will make little difference. However, consider:
typedef int (*intfp)();
intfp ptrarray[10];
You can't do that with #define.
--
"The N in NFS stands for Not, | Henry Spencer at U of Toronto Zoology
or Need, or perhaps Nightmare"| uunet!attcan!utzoo!henry henry at zoo.toronto.edu
More information about the Comp.lang.c
mailing list