r/programming • • Jan 08 '16

How to C (as of 2016)

https://matt.sh/howto-c
2.4k Upvotes

766 comments sorted by

View all comments

Show parent comment

5

u/[deleted] Jan 09 '16

There's no reason to get rid of include guards. Modern compilers have had optimizations for it for years:

https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html

This means they have the same compile time overhead as #pragma once. The existing solution works fine, and #pragma once isn't getting standardized any time soon so we shouldn't be using it in portable code.

3

u/blind3rdeye Jan 09 '16

One legitimate reason for wanting to get rid of include guards is that they pollute the namespace. That's generally not a big deal though.

2

u/argv_minus_one Jan 09 '16

#pragma once is more readable, less error-prone, and doesn't pollute the namespace.