Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Compiler design in C? Date: Thu, 10 Nov 2016 15:57:02 -0800 Organization: None to speak of Lines: 47 Message-ID: References: <87lgwrzvqt.fsf@gmail.com> <87lgwrdaiu.fsf@gmail.com> <87shqz7n08.fsf@gmail.com> <362fc76e-f4aa-4c66-abfd-ea4e8d87da47@googlegroups.com> <87y40ruk7u.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="b023963e5404d3dd517d4c8fc3e923ff"; logging-data="25197"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tI4D1Ypbsv/GFEU/c4BjM" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:inH+3AI9axbS2VHccC0uUtU/nWQ= sha1:9uRjBk0BPBBVzgYF1O5lcpftAlQ= Xref: csiph.com comp.lang.c:96362 jacobnavia writes: > Le 10/11/2016 à 23:28, Keith Thompson a écrit : >> I'd prefer to write: >> >> typedef MyPieceOfData ElementType >> #include "valarraygen.c" >> >> and as far as I can tell it should still work. > > Mmmm good idea. Thanks. > The only thing that I could argue in favour of the > preprocessor is that at the end of the include file I #undef > "MyPieceOfData" and I can't do that with a typedef. There is no > > forget(MyPieceOfData) > > to get rid of a typedef. Well, a typedef does vanish at the end of its scope. > But why would you want to get rid of the symbol in the first place? > > Could it clash with other symbols in the user's system? > > It is the programmer that decides that name so... I can't tell you right > now but maybe the typedef is better than the define, I have to think > about it. Somebody suggested that a macro could be used with token-pasting to generate unique function names. I haven't looked at your code closely enough to know whether that's an issue. I'm not suggesting that it's all that big a deal. I just prefer to use typedefs rather than macros if possible, both because of syntax issues (with array types, for example) and because it ... feels cleaner. Macros do give you some finer control over when you can redefine them. That can be good or bad. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"