Why (or why not) use pragma once over ifndef? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 11

Why (or why not) use pragma once over ifndef?

4th Mar 2019, 4:37 AM
Moses Odhiambo
Moses Odhiambo - avatar
2 Réponses
+ 9
Although #pragma once is less code to deal with (and less code to deal with == overall less bugs) and arguably widely practiced, it is non-standard. If portability is not your concern and you are not a total purist, then this shouldn't be an issue.
4th Mar 2019, 5:21 AM
Fermi
Fermi - avatar
+ 7
`#pragma once` isn't standard C++. I believe it used to be a Microsoft Visual C++ thing, but these days every major compiler can handle it. I don't see a reason not to use it, unless your compiler can't do it, or unless your code is used by many people (and hence many compilers).
4th Mar 2019, 5:15 AM
Schindlabua
Schindlabua - avatar