clap icon indicating copy to clipboard operation
clap copied to clipboard

replace pragma once with include guards

Open datajake1999 opened this issue 6 months ago • 9 comments

When attempting to compile src/main.c with TCC (the Tiny C Compiler), I am getting the following errors:

In file included from main.c:1: In file included from c:/tcc/include/clap/all.h:3: In file included from c:/tcc/include/clap/clap.h:30: In file included from c:/tcc/include/clap/factory/plugin-factory.h:3: In file included from c:/tcc/include/clap/factory/../plugin.h:4: In file included from c:/tcc/include/clap/factory/../host.h:3: c:/tcc/include/clap/factory/../version.h:14: error: struct/union/enum already defined

As pragma once is a non-standard C extension, I feel using include guards will help with cross-compiler compatibility.

datajake1999 avatar Jun 23 '25 15:06 datajake1999

Oh gosh do we use pragma once here?

You are totally correct it is non standard and we should replace it everywhere it is used

I have a script that does that. Let me talk with my collaborators in clap land about how and when to stage

baconpaul avatar Jun 23 '25 15:06 baconpaul

And thank you for reporting this!

baconpaul avatar Jun 23 '25 15:06 baconpaul

Why not fix tcc instead?

abique avatar Jun 23 '25 15:06 abique

It is probably a similar effort to fix tcc and add the old school header guard.

I'm against the old header guard.

abique avatar Jun 23 '25 16:06 abique

It must not be difficult, open tcc source code, find the preprocessor, it must have a hash table somewhere: macro name to definition, then just put next to it a hash set and impl #pragma once.

abique avatar Jun 23 '25 16:06 abique

Can you elaborate on why you don't prefer include guards? I personally don't see them as a problem.

datajake1999 avatar Jun 23 '25 16:06 datajake1999

The TCC source code seems to imply that there is support for pragma once:

https://github.com/TinyCC/tinycc/blob/2d4e4a69c44b7646ad62fa5f4eae6e88f92878a9/tcc.h#L1301

defiantnerd avatar Jun 23 '25 16:06 defiantnerd

I just built the fork of TCC that is on GitHub, and I was able to compile src/main.c without any problems. I was previously using the last official release of TCC from 2017, and it appears that version doesn't support pragma once.

datajake1999 avatar Jun 23 '25 18:06 datajake1999

Ugh I hate us not obeying the published standard

But that’s why we have multiple voices who decide!

Can we update the readme to say we are not standard c++ or c99 instead of fixing the pragma?

baconpaul avatar Jun 23 '25 19:06 baconpaul