Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: Macro does not work in source code. Date: Mon, 08 Aug 2011 09:15:48 +1200 Lines: 41 Message-ID: <9a8dk5Fef9U2@mid.individual.net> References: <44d8e695-c63d-4453-b405-4902416f265c@h14g2000yqd.googlegroups.com> <87r557n5fu.fsf@gmail.com> <7a284$4e357ef3$506c0d9c$25382@news.chello.at> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net olpy/+NXlNvLpOeXzYL+aAbHXvIDh8Sg4ZHWXG19zzpjR8Rkj0 Cancel-Lock: sha1:gMIBclpUbwjr+Kuef5qsUS55NyY= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:8557 On 08/ 8/11 08:50 AM, Alf P. Steinbach wrote: > On 07.08.2011 20:00, James Kanze wrote: >> On Aug 1, 9:11 am, "Alf P. Steinbach" >> wrote: >>> On 01.08.2011 08:58, Paul Brettschneider wrote: >> >>>> Especially in this >>>> case were it was suggested up-thread to use include guards *and* the >>>> #pragma. That's one more line for nothing. Old cruft like this should be >>>> supported for compatibility reasons, but also deprecated to make a point. >> >>> On the contrary, "#pragma once" is probably what one should use for new >>> code -- IN SPITE OF NOT BEING FORMALLY STANDARD. ;-) >> >> Only if you don't care if your code works on machines other than >> Windows and Linux. > > I think, if one needs to support a compiler that doesn't support > `#pragma once`, then one is in about the same kind of boat as one who is > targeting a 16-bit char system: one is not writing portable code. > > So, big difference between formal and practice. :-) > > But here's the crucial thing: if up-front generation of include guards > is feasible, and it is, then for those special compilers (like 16-bit > Digital Signal Processor compiler) it's no big deal to preprocess the > source replacing `#pragma once` with traditional include guards. Well my day to day compiler (Sun CC) does not use `#pragma once` and I have never seen it used in Unix, Linux or embedded system headers. In a way, `#pragma once` is an anachronism. The preprocessor can keep track of open headers with include guards and not reopen the file. Both Sun CC and gcc appear to be doing this. It is probably a worthwhile optimisation, I bet most of the headers encountered in a typical build are system or third party library headers that do no use `#pragma once`. -- Ian Collins