Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!zaphod.mps.ohio-state.edu!rpi!uupsi!njin!princeton!notecnirp!nfs From: nfs@notecnirp.Princeton.EDU (Norbert Schlenker) Newsgroups: comp.lang.c Subject: Re: typedef vs #define Keywords: difference Message-ID: <24495@princeton.Princeton.EDU> Date: 26 Feb 90 13:32:33 GMT References: <8430@cbnewsh.ATT.COM> <752@s5.Morgan.COM> Sender: news@princeton.Princeton.EDU Reply-To: nfs@notecnirp.UUCP (Norbert Schlenker) Distribution: usa Organization: Dept. of Computer Science, Princeton University Lines: 33 In article <752@s5.Morgan.COM> amull@Morgan.COM (Andrew P. Mullhaupt) writes: >In article <8430@cbnewsh.ATT.COM>, em@cbnewsh.ATT.COM (edward.man) writes: >> >> The question is: >> >> Consider the following two C statements: >> 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? > >If your code compiles, it shouldn't result in different object code... But beware. If we change the question only slightly, to: Consider the following two C statements: 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? Now there's a considerable difference between the two. Imagine the declaration: FLAGS x, y; The typedef results in (probably) what people expect, namely that both x and y are pointers to short int. The #define makes x a FLAGS and y a short, probably not what you want.