Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: typedef vs #define Message-ID: <1990Feb24.234433.14252@utzoo.uucp> Organization: U of Toronto Zoology References: <8430@cbnewsh.ATT.COM> Date: Sat, 24 Feb 90 23:44:33 GMT In article <8430@cbnewsh.ATT.COM> em@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@zoo.toronto.edu