in , , , ,

POV: you’re learning C++ (you regret this deeply)

POV: you're learning C++ (you regret this deeply) | bugs-memes, c++-memes, bug-memes, performance-memes, warning-memes, error-memes, fix-memes, search-memes, compiler-memes, IT-memes, rds-memes, mac-memes, bot-memes, header-memes, cookie-memes | ProgrammerHumor.io
bugs-memes, c++-memes, bug-memes, performance-memes, warning-memes, error-memes, fix-memes, search-memes, compiler-memes, IT-memes, rds-memes, mac-memes, bot-memes, header-memes, cookie-memes | ProgrammerHumor.io

Content

Ijust wanted to add to this discussion that I am just compiling on VS and GCC, and used to use include guards. I have now switched to pragma once, and the only reason for me is not 199 performance or portability or standard as I don’t really care what is standard as long as VS and GCC support it, and that is that: pragma once reduces possibilities for bugs. It is all too easy to copy and paste a header file to another header file, modify it to suit ones needs, and forget to change the name of the include guard. Once both are included, it takes you a while to track down the error, as the error messages arent necessarily clear. Share Follow edited Nov 30, 2014 at 9:57 answered Jul 22, 2011 at 16:55 Cookie 11.7k 13 52 81 5 This is the correct reason. Forget performance–we should use pragma once because it’s less error prone. It occurs to me that if compilers are already tracking include guards, they’re already doing most of the work necessary to issue warnings when they see different files using the same macro name. – rieux Jun 13, 2019 at 6:36 Add a comment pragma once has unfixable bugs. It should never be used. 169 If your include search path is sufficiently complicated, the compiler may be unable to tell the difference between two headers with the same basename (e.g. afoo.h and bfoo.h), so a pragma once in one of them will suppress both. It may also be unable to tell that two different relative includes (e.g. include "foo.h" and include "..afoo.h" refer to the same file, so pragma once will fail to suppress a redundant include when it should have. lanc arca attocic tho commorc amia