Macro does not work in source code.

I

Ian Collins

I think, if one needs to support a compiler that doesn't support
`#pragma once`, then one is in about the same kind of boat as one who is
targeting a 16-bit char system: one is not writing portable code.

So, big difference between formal and practice. :)

But here's the crucial thing: if up-front generation of include guards
is feasible, and it is, then for those special compilers (like 16-bit
Digital Signal Processor compiler) it's no big deal to preprocess the
source replacing `#pragma once` with traditional include guards.

Well my day to day compiler (Sun CC) does not use `#pragma once` and I
have never seen it used in Unix, Linux or embedded system headers.

In a way, `#pragma once` is an anachronism. The preprocessor can keep
track of open headers with include guards and not reopen the file. Both
Sun CC and gcc appear to be doing this.

It is probably a worthwhile optimisation, I bet most of the headers
encountered in a typical build are system or third party library headers
that do no use `#pragma once`.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top