r/C_Programming • • 22d ago

Could someone explain the practical differences between #pragma once and traditional include guards (#ifndef, #define, and #endif)?

81 Upvotes

58 comments sorted by

View all comments

1

u/AnToMegA424 21d ago

I always thought it was that #pragma once was only supported on Windows, though it was slowly getting "adopted" elsewhere, meanwhile #ifndef #define ... #endif was supported everywhere and was a better practice generally speaking as it's a safer, more portable approach
I'd never really understood

Guess I'm wrong and didn't understand the first time I heard about it either lol
The reason not being what I just said would probably explain why I saw #pragma once at the start of every generated file in Unreal Engine 5