For unity builds is there any tradeoff/correctness issues between #pragma once vs include guards [duplicate]

1 week ago 13
ARTICLE AD BOX

Suppose I have a unity build:

//impl1.h //impl1.cpp -> #include s impl1.h //impl2.h //impl2.cpp -> #include s impl2.h AND impl1.h //main.cpp #include "impl1.cpp" #include "impl2.cpp" int main(){ //stuff }

Does it matter that impl1.h is like so:

#ifndef IMPL1_H #define IMPL1_H //impl1.h stuff #endif

as opposed to

#pragma once //impl1.h stuff

The reason I ask is that the semantics of the header guard seem to me to make it absolutely certain that

#include "impl2.cpp"

does not again process impl1.h. With #pragma once, and assuming #include " " engages in more or less plain straightforward textual substitution, are there issues with the compiler seeing multiple #pragma onces corresponding to the same or different header files when it processes main.cpp ?

One_Cable5781's user avatar

3

Read Entire Article