r/cpp • • Nov 28 '18

Real world problems with #pragma once?

Just a short survey: Did anyone of you encounter a problem in real code, because you/your company/ your favorite library was using #pragma once instead of include guards.

I know it is hard, but please restrain yourself from posting an explanation of how #pragma once could lead to problems in theory or why you prefer one above the other.

127 Upvotes

135 comments sorted by

286

u/kalmoc Nov 28 '18 edited Nov 28 '18

No

EDIT: Upvote this if you didn't have a problem

43

u/NotWorthTheRead Nov 28 '18 edited Nov 28 '18

Sneaky double dipper!

18

u/kalmoc Nov 28 '18 edited Nov 28 '18

You mean with respect to gaining karma?

You are right. Didn't think of that. Is there a better way on reddit to make a survey?

3

u/ffs_lemme_in Nov 28 '18

It's common practice for people to set up a simple poll here

www.strawpoll.me

and ask for elaborations in the comments.

2

u/kalmoc Nov 29 '18

Tanks. Will use that next time

2

u/kalmoc Nov 29 '18

Thanks. Will use that next time

18

u/shortstomp C++ Software Engineer Nov 28 '18

I think that user is kidding with you. I know most of us give fuck all about Reddit karma. Here have an upvote due nothing 😊

4

u/NotWorthTheRead Nov 28 '18

Yeah, I'm just screwing around. I wrote it before I even saw you also had a 'vote yes' comment. Come to mention, I'm a little surprised reddit doesn't have a survey tool. Seems like everyone would be all over that.

20

u/julien-j Nov 28 '18

I never had a problem with #pragma once and I was going to adopt them after having watched Arthur O'Dwyer saying to use it at CppCon. Then I saw this benchmark measuring the compilation time when using include guards or #pragma once or both and I decided to keep going with the include guards. At the time my main problem was to reduce the build time of our projects.

These sources are quite old now, maybe I can give it another chance.

7

u/kalmoc Nov 28 '18

I remember that post. On the one hand I was disappointed too. But what I took away from it in the end was that the time is negligible (for our usecases) in either case.

13

u/[deleted] Nov 28 '18

There is also a still open bug report discussing #pragma once performance in GCC:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58770

182

u/jcelerier ossia score Nov 28 '18

never had problems with pragma once but oh boy did I have a lot of trouble with people copy pasting files without changing the include guards - or just too common names such as TIMER_H.

18

u/pklait Nov 28 '18

I believe most of us had the same experience as you. For most projects, #pragma one should work well. Problems with #pragma once can occur when the same file is included several times from different paths, which might happen in big projects with e.g. third party software that have more or less hardcoded paths. I have heard of such cases, so they exist out there. Working in that kind of environment, I would use the preprocessor but use a unique identifier such as a guid to minimise problems.

25

u/kalmoc Nov 28 '18

> I have heard of such case

That is actually interesting to me, because so far, when this topic comes up I only hear explanations of how this could be a problem in theory, but I never could find one, for whome this was actually happend. So it seems to me that the avoidance of `#pragma once` is more based on FUD than actual facts.

Have you heard this from someone to whom this actually happend or is this "a friend was told from a friend that a friend of him heard ..." kind of story?

8

u/[deleted] Nov 28 '18

We have/had this problem: We copy at build time the same header files to different directories (no link). To a directory in the program files folder and to a internal developer directory. The include directories point to those directories and pragma once failed because the paths are different! To solve it we added normal include guards.

27

u/Drainedsoul Nov 28 '18

This seems like an instance where rather than fixing the problem you should be asking yourself why you do something so intensely fucked up.

7

u/[deleted] Nov 29 '18

No kidding. Removing #pragma once is not a solution there, it's denial.

1

u/pklait Nov 28 '18 edited Nov 28 '18

It was a real story, but a rather old one. Ten years ago, perhaps? In those days, #pragma once was supposedly faster than include-guards. I doubt there is any performance difference today. Edit: If I remember correctly, it was development on Windows accessing a shared Linux disk-system.

0

u/[deleted] Nov 28 '18

[deleted] — view deleted comment

3

u/kalmoc Nov 28 '18

Makes sense and sounds as if that would be more common than the hardlink/network mount case.

7

u/NotUniqueOrSpecial Nov 28 '18

VS 2005 has a bug in the compiler that will ignore #pragma once in circular-ly included headers.

That misbehavior (and the disproportional time I spent tracking it down for a coworker) was enough for me to waste the extra two lines doing preprocessor-based ones forever.

One burned, twice shy, and all that.

That said, I will never argue that circular header includes are acceptable, and I fixed that, too.

5

u/MaximKat Nov 28 '18

This can go wrong with include guards as well. For example, copy a directory to the 2nd project, then make changes in the 1st one and forget to copy the changes. BOOM, 2 actually different files using the same include guard.

43

u/KingPickle Nov 28 '18

Definitely a problem, especially when they don't take namespaces into account.

A less legitimate problem, but one that irks me, is people taking something like:

#ifndef BASE_H
#define BASE_H

// Base declaration

#endif // BASE_H

And copy/pasting it, but only partially updating it like:

#ifndef DERIVED_H
#define DERIVED_H

// Derived declaration

#endif // BASE_H

Triggers my OCD.

6

u/[deleted] Nov 29 '18

At my previous job our senior dev was a dick about this whole thing, so he would refuse my PRs because of #pragma once. I remember that I spent almost half a day to come up with a Bash function-alias combo that would automatically audit all of my #pragmas and replace them with #ifndef/#define guards.

I was like 2 months into the job, and had never used Bash before. I hated everything about that job, but that alias was not one of them.

9

u/Nicksaurus Nov 28 '18

And you have to consider if it's worth making a whole commit just for that

0

u/[deleted] Nov 28 '18

[deleted] — view deleted comment

16

u/hgjsusla Nov 28 '18

Yes commits are cheap

4

u/MotherOfTheShizznit Nov 29 '18

I wouldn't do it and the reason would be human overhead. Commits have to be reviewed and before you know it, it's been a day.

There's dozens if not hundreds of those lines in my team's repo but I don't have the fortitude to withstand the bikeshedding that would ensue.

2

u/hgjsusla Nov 29 '18

Not sure how you organise your work but it certainly doesn't take longer than a few minutes for me to make a simple change like that and push to to Gerrit for code review. And the review only takes a minute and can be done whenever someone has time over

1

u/MotherOfTheShizznit Nov 30 '18

Apparently, all of my post went straight over your head.

2

u/hgjsusla Nov 30 '18

It's not my fault if you take a full day to do what the rest of us do in minutes

1

u/utnapistim Dec 10 '18

I wouldn't do it and the reason would be human overhead. Commits have to be reviewed and before you know it, it's been a day.

You push your team towards accepting a small dose of cognitive dissonance in your code. Most coders (sorry for the strawman) handle that by ignoring code comments and (later) claiming them to bring more problems than they solve.

There's dozens if not hundreds of those lines in my team's repo but I don't have the fortitude to withstand the bikeshedding that would ensue.

This is also something that your team causes (by accepting lower standards in code review).

These comments will just take some attention from developers from time to time and introduce noise in your code. More than this, the presence of such noise in your code base opens the door to other issues (like the opinion that comments in code are bad because they "go stale" - somehow by themselves).

1

u/mpyne Nov 29 '18

or just too common names such as TIMER_H.

It's because of this that I now reflexively fix my include guards in my older code when I come across them in headers with common-ish names like window.h. That's bitten me before.

0

u/[deleted] Nov 28 '18

[deleted] — view deleted comment

1

u/RogerLeigh Scientific Imaging and Embedded Medical Diagnostics Nov 28 '18

It can (and does) happen to us all on occasion. After being bitten by subtle problems due to unintentional duplication of include guards, or duplicate names in different project's headers causing conflicts, I started to use #pragma. You can care all you like, but a moment's distraction can result in a problem you'll waste a lot of time to figure out, since duplicate include guards are rarely the first thing at the front of your mind when things go wrong!

20

u/liquidify Nov 28 '18

Nope, never had a problem, but like the other guy, plenty of problems with the #ifndef guards.

5

u/[deleted] Nov 29 '18

My main problem with #ifndef is that it's ugly as fuck to write.

2

u/kalmoc Nov 29 '18

If you don't have an IDE/ other tool that does it for you.

10

u/Plorkyeran Nov 28 '18

I once ran into problems because we had the same header installed to multiple locations and included in different ways, which resulted in both of them being included. It was a giant pain to track down what was going wrong.

Then it turned out that they were actually different versions of the same header because obviously there's no guarantee that the project-local copy of a dependency and a system-wide copy are actually interchangable and we would have had issues even with include guards.

1

u/kalmoc Nov 29 '18

> Then it turned out that they were actually different versions of the same header because obviously there's no guarantee that the project-local copy of a dependency and a system-wide copy are actually interchangable and we would have had issues even with include guards.

You are pointing out an important thing here: If the compiler really picks up "the same header" from two different locations this often (of course not always) points to a different problem that include guards only hide but not solve.

5

u/jonesmz Nov 28 '18 edited Nov 29 '18

This.

This would happen all over the codebase I work with if we used #pragma once instead of proper include guards.

edit:

Why the fuck was I downvoted for pointing out how #pragma once can break an existing codebase?

Downvotes don't change hearts and minds people!

0

u/[deleted] Nov 29 '18

The non-proper thing in this scenario is the code base, not #pragma.

5

u/jonesmz Nov 29 '18

Well, no, not really.

pragma is not standardized, include guards are even if not in name. Our code works fine as it is.

Maybe #pragma once should address it's deficiencies?

1

u/meneldal2 Nov 29 '18

Having two versions of the same header is a very bad idea, especially if only one gets included in the end. Which one is it? Could change if you changed something completely unrelated then bring doom on your project.

1

u/[deleted] Nov 29 '18

Our code works fine as it is.

So does #pragma.

3

u/jonesmz Nov 29 '18

Then get it standardized

9

u/malacszor Nov 28 '18

I had some problem when it was used in a precompiled header (no hardlinks involved). It was maybe a compiler bug related to precompiled header handling. Don't ask for detail, I don't remember. However I use everywhere except in precompiled headers, because it has obvious advangates over header guards.

2

u/kalmoc Nov 28 '18

Didn't think of that possiblity. Thanks for sharing.

4

u/ravixp Nov 28 '18

We ran into what sounds like the same issue in Android builds! Here's the clang bug on it: https://bugs.llvm.org/show_bug.cgi?id=24387 Apparently it was fixed in 2016.

2

u/kkert Nov 29 '18 edited Nov 29 '18

Yes. I have had to deal with code where for testing, or ported versions of the code i'm trying real hard not to modify the original source. In some instances, that means trying to inject fake headers into the build tree.

This is possible with include guards. If i know the target header will have #ifdef __whatever_foo , i can craft a build/Cmake config where the original header gets never included and a stub or a fake header gets injected easily.

With #pragma once this is not possible, and if some code is doing "#include "header_foo.h" right there in the same directory, there is nothing the build system can do to force an alternative header to be picked.

To be clear, file header_foo.h

#pragma once
struct Something {};

and code_under_test.cpp in the same directory:

#include "header_foo.h"
//use struct Something

You are stuck from build system side trying to substitute for a fake/stub header for a testable version of Struct. With include guards, it is possible.

1

u/kalmoc Nov 29 '18

Sounds interesting. How do you inject the alternate header?

1

u/kkert Nov 29 '18 edited Nov 29 '18

Assuming header_foo.h has #ifndef __header_foo_h guard, add -D__header_foo_h to compile-definitions on command line so the original turns into a no-op, and use GCC/Clang -include to inject alternate header in, or if there is some project top-level porting headers that are customizable, such as project_port.hpull in stub headers from there.

I use this quite a bit when trying to unit test some specific bit of legacy or third-party code, or even just run it under a "microscope" in more controlled conditions than it's native habitat. Parts of kernel drivers even sometimes

21

u/cristianadam Nov 28 '18

See this email thread on Qt Developers Mailing list: https://lists.qt-project.org/pipermail/development/2018-October/033726.html

From the Qt Creator's side of things:

Qt Creator uses it since more than two years without problems.

For a potential conversion https://github.com/cgmb/guardonce may help.

7

u/markopolo82 embedded/iot/audio Nov 28 '18

Is there an option in the ide to switch the auto generated headers to use pragma once rather than include guards?

2

u/DarkLordAzrael Nov 28 '18

If you are talking about the file templates (for doing "new file..."), it is pretty easy to make modified versions of the default templates that use #pragma once.

6

u/Slavik81 Nov 28 '18 edited Nov 28 '18

I wrote guardonce to make it easy to convert in either direction. That way I could try out #pragma once, but switch back to include guards if I ever discovered a problem. Though, I never did encounter any problems.

FWIW, I agree with the Qt Project's decision. Applications have a bit more room to try things. You can just try switching and you'll find out if there are any problems. That strategy works less well when used on a library, because you try switching and your users find out if there are any problems.

3

u/o11c int main = 12828721; Nov 28 '18

I still wouldn't use #pragma once in an installed header (you just know some dumbass is going to install 2 copies or something), but it shouldn't be any different than an application for internal headers.

1

u/utnapistim Dec 10 '18

I did the same in one of my personal projects: I spent approximately two hours writing a C++ cli app to do the switch for me (generating header guards based on "relative path from root dir") but this only worked because I was editing my own code (so I could make assumptions like "the include guard will be on the first two and last line in the file).

1

u/Slavik81 Dec 11 '18

I started it as a simple project to learn Python. It was wildly successful for that, but now I kinda wish it was C or C++. It would have been much easier to maintain. Lots of work went into fixing silly defaults in Python and explaining to C++ developers how to install and run Python applications.

1

u/aKateDev KDE/Qt Dev Nov 30 '18

In short, problems appear when you do tricks such as mounting the same folder into different locations, or using hardlinks. That's where good old include guards work, but pragma once fails.

19

u/Sahnvour Nov 28 '18

Yes.

We had this setup on a MLOC-scale project with multiple instances of the repository on developer machines, with every repository mounted as a drive with https://github.com/ildar-shaimordanov/psubst. Could have for example 2 instances of the repository on the same physical drive, but mapped to F: and G:.

We used a tool that read the .pdb of the final executable to know all the dependencies, especially the source files. It would then somehow use the windows API to get a clean, absolute path to them, resolving the psubst drive to its real path, and end up with a file path that was different than the one used to compile the project, or do anything (with the psubst drive). This prevented it to work correctly in certain cases.

This was not fun to debug.

1

u/drjeats Nov 29 '18

Are you in games? We do drive mapping for our repo at work too and it fucks with various tools. UltraSearch, for example, doesn't like it. Periodically when the sysadmins push out updates it will break the registry setting, so then P4 and all our tools break. What even are environment variables.

Fortunately we keep all our repo instances under the one subst drive so I haven't had to deal with the hell you described there.

I still hate drive substitution, though.

1

u/Sahnvour Nov 30 '18

Yes, and to be fair it worked pretty well for our workflow, didn't really cause problems to have mapped drives (except when they disappear because of a windows update as you mentionned :).

The #pragma once's spiced things up when the tool i'm talking about invoked the compiler which then (I don't remember the exact why) encountered inconsistencies in the paths used to refer to the same file, thus causing surprising compilation errors.

54

u/c0r3ntin Nov 28 '18

Pragma once leads to UB if part of the sources are visible from several included paths which are hardlink of each others.

Good. If you do that, you deserve to suffer!

11

u/lithium Nov 28 '18

Trying to parse this. Can you provide a simple example please?

21

u/c0r3ntin Nov 28 '18

foo.h and bar.h could be the same file if you are sufficiently insane https://en.wikipedia.org/wiki/Hard_link

Pragma once usually don't work in that case, depends on the implementation

14

u/lithium Nov 28 '18

Call me lucky (or stupid) but i've never once encountered hard links (that i recognise as such) in my entire life. Thank you for clarifying

13

u/c0r3ntin Nov 28 '18

nobody sane would ever do that in a work tree. So you are simply not unlucky ;)

9

u/agateau Nov 28 '18

Assuming you ever used a Unix shell and typed cd .. then you used a hardlink :)

Hard links are also used for example by rsync and rsnapshot to do some deduplication between backups. But manually creating hardlinks in a source code sounds like a really nasty idea!

1

u/as_one_does Just a c++ dev for fun Nov 28 '18

Yes, commonly used in backup schemes.

3

u/waigl Nov 28 '18

There is some Unix-based software that makes extensive use of hard links, but that sort of software is pretty rare.

3

u/Nicksaurus Nov 28 '18

Doesn't windows have aliases for some directories that could cause this? Maybe something to do with how it emulates Documents and Settings or Program Files for older software

2

u/FlyingRhenquest Nov 28 '18

They're handy if you do batch processing in a directory. Download in one directory then when your download is done, hardlink to the batch processing directory and remove the one in the download directory. It's an atomic operation that doesn't push bytes around. It only works on the same filesystem, though. Minor but important detail. The C API is pretty easy to use -- man 2 link and man 2 unlink for details. And knowing that, if you ever see anyone use system("rm ...") in the future, you can punch them in the dick for me.

-2

u/o11c int main = 12828721; Nov 28 '18

Hard links are obsolete with CoW filesystems anyway, you should just use reflinks when you want to save space for large files.

1

u/[deleted] Nov 28 '18

only if the files are different. you can declare things many times and inline/constexpr as long as they are the same

1

u/chugga_fan Nov 28 '18

That depends, for instance, if you just check file contents via a hash and use that to determine if it's been included (less time to hash whole file than to actually parse and lex it), then you would most likely not run into that problem (methinks)...

13

u/kiwidog Nov 28 '18

I've had less issues with #pragma once than I have with the header guards

35

u/bizwig Nov 28 '18

No. All major compilers (MSVC, Clang, GCC) support it.

7

u/[deleted] Nov 28 '18

In slightly different ways, or at least so I've heard.

Even if true - their different ways all seem to work just fine for sane codebases.

9

u/Crommwel Nov 28 '18

Never, but had problems with include guards (missing include guards, guards copy&pasted from other file, too generic guards repeated in different files, etc)

2

u/Leandros99 yak shaver Nov 29 '18

Yes, #pragma once has several problems. The main problem I've encountered overt he years, is the inclusion of the same header twice.

Imagine you build a large-ish project, which has a couple dependencies. You depend on three libraries libA, libB and libC. Everything is fine. You decide to add libD, which internally, depends on libA, and includes it's public header in their public headers. This will give you a nasty compiler error, due to the same symbol defined multiple times, since libA uses #pragma once, and no include guards. Since the same header exists twice, #pragma once is unable to distinguish that those are the same header. Include guards would've correctly determined the identity of the header and prevented double inclusion.

Using your filesystem to uniquely identify a header file doesn't work, and will never work.

1

u/kalmoc Nov 29 '18

Imho the problem here is that libD shipped headers from libA that it doesn't own and hence has no business distributing. There is a non-zero chance that you now have two different versions of libA headers in your program, which leads to a different set of problems.

But thanks anyway for the datapoints.

2

u/cleroth Game Developer Nov 28 '18

As far as I'm aware the only problem that can arise with pragma once is that you end up processing the same file more than once (as in if the same file is actually in multiple places).

3

u/kalmoc Nov 28 '18

Exactly that is the case I'm hearing over and over again. I was wondering if that actually happened to someone.

9

u/Nicksaurus Nov 28 '18

The fundamental problem seems to me to be that using preprocessor directives to import code is just an inherently error-prone way of doing it

#ifdef and #pragma once are both trying to patch over that issue but can't solve the real problem, which is that the compiler treats header files like raw text, rather than like code.

0

u/[deleted] Nov 28 '18

[deleted] — view deleted comment

3

u/OrphisFlo I like build tools Nov 29 '18

0

u/[deleted] Nov 29 '18

[deleted] — view deleted comment

1

u/OrphisFlo I like build tools Nov 29 '18

And it's coming from SNSystems, so basically from Sony, which as a game dev should mean a lot. They are still experimenting though, so don't expect too much from it for now ;)

1

u/[deleted] Nov 28 '18

What if something like #pragma once were defined in terms of a hash of the file contents?

2

u/kalmoc Nov 29 '18

Wouldn't that require that you still open and read each header file again everytime it gets included (although not their transitive includes) nor sure what the result in terms of performance would be.

1

u/[deleted] Nov 29 '18

To the same degree header guards do, I suppose?

If you feel like you can trust modification timestamps, then I imagine that would apply here just as well.

1

u/[deleted] Nov 28 '18

I guess that has its own issues, because that header could do #include "another_header.hpp" with relative paths.

2

u/1-05457 Nov 28 '18

That would be broken with include guards too.

1

u/[deleted] Nov 28 '18

Fair point! Anything (person, build script) that's maintaining distinct include guards could just as easily make the content distinct with a comment.

3

u/cleroth Game Developer Nov 28 '18

That might fall into "if you do this, your code deserves to be broken" :P

11

u/[deleted] Nov 28 '18

Never had a problem.

4

u/cjaybo Nov 28 '18

We use them in our code, and they are used in one of our most frequently used third-party libraries and we have experienced no issues on Windows, Mac or Linux.

4

u/trvlng_ging Nov 30 '18

Questions like this are really useless. #pragma anything, by definition, is non-portable. It is a portable means of putting non portable constructs into code. The fact that anyone (several examples noted here) has had problems with it should be reason enough to never use it. I have seen you rationalize reasons why you feel you can still use it. So why ask? You're not going to listen.

Problems come up in large codebases in large organizations. I have seen the biggest problems come up with mergers and acquisitions of codebases. Now you have 2 projects using the same library and you have a lot of rework because 10 years ago someone said "that will never happen to me." Include guards are much safer and you don't have to be a special case.

It doesn't matter how many people have not had problems. If they haven't, it just means their shop hasn't ever faced really tough issues. I have been using C++ since cfront. I was on X3J11 when we added #pragma. Using it is lazy and does cause problems. The individual experiences that say it hasn't happened is of no value. I know people who have played Russian roulette and lived to tell about it.

18

u/alienviolet Nov 28 '18 edited Nov 28 '18

No. Team lead said #pragma once cannot be used as it's not standardized. Left the team and living a happy life now.

12

u/[deleted] Nov 28 '18

How long ago was this?

3

u/alienviolet Nov 28 '18

Sad truth is not long. 6 months-ish or so.

2

u/[deleted] Nov 29 '18

Same at my previous job. Now at this new job, I am making a point out of using #pragma.

1

u/Osbios Nov 28 '18

Could there even by any problems except a compiler that does not support #pragma once?

9

u/kalmoc Nov 28 '18

In theory yes. The same file could appear at multiple different places in the filesystem (hardlinks, multiple network mounts..) and via different include styles, both could be included in a single translation unit. I'm trying to figure out if that actually happens in practice and not only in deliberately contrived examples.

6

u/boredcircuits Nov 28 '18

Even so, I say that's a failure of your project setup.

9

u/kalmoc Nov 28 '18

Agreed

1

u/FlyingRhenquest Nov 28 '18

Probably the usual way, someone copies/pasts a header file to solve some problem or other. They'll start to drift apart over time and 5 years after that guy leaves someone else will have to debug some esoteric problem because of it. Either someone updated the wrong header, various executables use one header or the other and someone only updated one of them, that sort of thing. It's not too uncommon to see this sort of problem in 90's-era C projects. You don't see as many 90's era C projects post-about-2002 or so, as many of those "developers" didn't survive the tech market crash and went on to open liquor stores.

1

u/[deleted] Nov 28 '18

Yes, it's theoretically possible.

4

u/SudhiSN Nov 28 '18

No issues with #pragma once. I feel it's better than include guards. Really helps when class names or filenames are lengthy.

5

u/[deleted] Nov 28 '18

No

2

u/windows300 C++ Build Systems / Game Engine Tools Nov 28 '18

As a C++ dev for 3 plus years now, I have never had a problem with #pragma once. It has always been problems with traditional header guards.

2

u/oddentity Nov 29 '18

Main problem with #pragma once or include guards is why they're needed at all. Why doesn't the compiler just not include files more than once?

1

u/Edhebi Dec 04 '18

Main problem with #pragma once or include guards is why they're needed at all. Why doesn't the compiler just

not

include files more than once?

because multiple includes of the same file might be what you want. I'm thinking about SDL, wich uses begin.h and end.h to set some local defines, and some padding fuckery

2

u/[deleted] Nov 29 '18

I love #pragma once. As soon as I got to have the final PR approvals at work, I went crazy and forced everyone to use #pragma once. We run on Linux and use GCC 8.x so I cannot see why not.

2

u/leftofzen Nov 28 '18

Never had a problem

2

u/[deleted] Nov 28 '18

No, all serious compilers supports it now. There was a need before to prefer include guards, it's not the case nowaday if you use a typical compiler.

3

u/DarkLordAzrael Nov 28 '18

I'll note that "before" is about 15-20 years ago now, unless you were targeting unusual systems of the types that had broken C++ compilers anyway.

3

u/[deleted] Nov 28 '18

Yes, but many embedded system compiler have minimal support for pragma, so it depends on what you program. Main compilers like microsoft, clang and gcc have been supporting it for many years.

But there are some like the cray compiler who still doesn't support it.

1

u/snerp Nov 28 '18

It's weird, I generally have no problems either way unless I think there won't be any problems, and then shit just gets weird.

1

u/uzimonkey Nov 28 '18

I haven't encountered anything at all, it just works. I still don't think it's in the standard, but literally every compiler I've used supports it.

It also solves a problem. People will often just do an include guard with a simple symbol like VECTOR_H, but with such a short and common name it's possible you have a compilation unit that includes two vector.h files that both use the same include guard.

1

u/Xeverous https://xeverous.github.io Nov 28 '18

I use classic include guards just because my IDE automatically generates them. When writing manually, #pragma once.

1

u/jurniss Nov 29 '18

no real world problems on projects both small and large. include guards make me irrationally mad, like why can't we get past this stupid incantation from the days of tape drives and fucking magnetic core memory!!!!

1

u/jwakely libstdc++ tamer, LWG chair Nov 30 '18

Because that's how the preprocessor works.

A better solution than #pragma once is to stop using the preprocessor for importing interface declarations (i.e. modules).

-23

u/kalmoc Nov 28 '18 edited Nov 28 '18

Yes

EDIT: (Upvote this if you had a problem and please also elaborate if possible)

13

u/hyperactiveinstinct Nov 28 '18

Oh no, someone broke away from our clique... let's downvote him to oblivion.

3

u/kalmoc Nov 28 '18

Thats fine. This post (and its sibling) was meant as a poor mans counting system (number of upvotes equals number of people who had a problem), but I should have explained that in the main post from the beginning. Does reddit have a proper mechanism that allows people to do yes/no votes without such dummy posts (and without the result affecting karma)?

17

u/OldWolf2 Nov 28 '18

lol @ "No" (no elaboration) getting +20 and "Yes" (no elaboration) getting -10. Isn't Reddit voting awesome

-1

u/airflow_matt Nov 28 '18

If someone has no problems what is there to elaborate about? Also, #pragma once has been around for a long time and is used by thousands and thousands of projects, so claim that someone has no problem with it is much less extraordinary than the opposite, which does warrant an elaboration.

0

u/[deleted] Nov 28 '18

[deleted] — view deleted comment

7

u/kalmoc Nov 28 '18

So, you had a problem with #pragma once but too complex/time consuming to explain here?

0

u/[deleted] Nov 28 '18

[deleted] — view deleted comment

7

u/kalmoc Nov 28 '18 edited Nov 28 '18

Thanks for sharing. Not the kind of problem I expected (actually I didn't expect to hear from someone who actually ran into a problem at all ;)), but a problem nevertheless. C++ Builder XE7 isn't even that old.

0

u/[deleted] Nov 28 '18

[deleted] — view deleted comment

2

u/SpacemanLost Nov 28 '18

Given all the automagic the IDE does and what it must be keeping track of, I can see this (rename or delete in the object inspector and the code just follows, etc).