r/C_Programming • u/Yuki_pop • 22d ago
Could someone explain the practical differences between #pragma once and traditional include guards (#ifndef, #define, and #endif)?
81
Upvotes
r/C_Programming • u/Yuki_pop • 22d ago
View all comments
1
u/AnToMegA424 21d ago
I always thought it was that
#pragma oncewas only supported on Windows, though it was slowly getting "adopted" elsewhere, meanwhile#ifndef #define ... #endifwas supported everywhere and was a better practice generally speaking as it's a safer, more portable approachI'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 onceat the start of every generated file in Unreal Engine 5