discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Converting from #ifndef/#define include guards to


From: Douglas Geiger
Subject: Re: [Discuss-gnuradio] Converting from #ifndef/#define include guards to #pragma once globally
Date: Sun, 23 Feb 2014 15:06:56 -0500

Oh #pragma once - that old chesnut: if you have a few hours you can follow the various discussions on stackoverflow on it. I think it is at least enlightening to read through this answer on why it is *not* part of the ISO C/C++ standards: http://stackoverflow.com/a/1696194

I will note that on MSVC people have found compile-time improvements by using #pragma once - although it tends to only be noticeable in pathological cases. Still - an important feature for people going through the edit/compile/debug cycle.

My personal opinion on this is if there is a change to be made, it should be to use both: prepend #pragma once to header, and still include the #ifndef/#endifs that are present: it takes advantage of the speedup for compilers that don't automagically recognize #ifndef/#endif header guards (e.g. non-GCC compilers), while simultaneously it doesn't rely on non-standard compliant compiler features (which I'll argue we don't want to introduce *new* non-standard things into the codebase).

I'm all for doing things that decrease bugs due to bad copy/paste errors (especially since I seem to make those types of mistakes all the time), but relying on any compiler feature that is not part of the standard should be be *very* carefully considered. We support too many platform/compiler-combinations to take such things lightly.

 Doug



On Sun, Feb 23, 2014 at 2:52 PM, Michael Dickens <address@hidden> wrote:
I'll second what Moritz wrote: Since this pragma is "non standard but widely supported", let's stick with the header guards since they are guaranteed to work even with very old C / C++ compilers ... if someone wants to -also- use this pragma that's fine; having both should not hurt.  I'd prefer to not rely on just the pragma ... my US$0.02 worth, if even that much ;) - MLD

On Feb 23, 2014, at 2:03 PM, Moritz Fischer <address@hidden> wrote:
> some quick Google research found several contradictory sources. [1]
> calls it 'non standard but widely supported'.
> Since we build on weird platforms I think we should make absolutely
> sure that this is the way things should be done ^{TM}.
> Some other sources listed this as a potential speedup for compilation
> on Visual Studio. Discuss.
>
> Personally I don't have an issue with header guards because there
> exist plenty of plugins for {vim,emacs, whatever},
> to do it for you.

_______________________________________________
Discuss-gnuradio mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio



--
Doug Geiger
address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]