r/C_Programming • • 27d ago

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

79 Upvotes

58 comments sorted by

View all comments

Show parent comment

3

u/Emotional-Audience85 26d ago

I don't think he said anything of the sort

0

u/Huuf 26d ago

I interpreted this text as such:

in my opinion, if you have this problem where you are somehow getting the same header included through different paths there is something wrong with your file layout in most all cases (others are free to disagree).

3

u/Emotional-Audience85 26d ago

I interpreted it has having the file included through different physical paths (e.g. one is a symlink to the same file).

I've never encountered this but I believe it may be an issue for #pragma, as the same file may be treated as 2 different files and the content be pasted twice, leading to compilation errors

1

u/Huuf 26d ago

If that is meant, I totally agree,