I think it’s a great idea to add something like:
#include_once

In my opinion it would be easier to use since you could look only at your included files and know immediately that it is only included once.

Something like that would be difficult to articulate to the community and maybe committee since modules overlap with this functionality of import/include.
But people are not updating or changing the way they program so eagerly, changing include to include_once would be easy to make with immediate effect.

I don’t know how compiler could manage it, perhaps creating hash for each file and comparing it later with every include?

Cheers, Filip

Wiadomość napisana przez Sebastian Wittmeier via Std-Proposals <std-proposals@lists.isocpp.org> w dniu 23 mar 2025, o godz. 08:42:

 AW: [std-proposals] #pragma once safer alternative

Are you talking about #include being differently handled by the pre-processor than #pragma?

And/or about different preprocessing phases and handling of macro expansion?

 

You are using #include once inside a condition, is this on purpose for showing some difference to #pragma once?
 

-----Ursprüngliche Nachricht-----
Von: Muhammad via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: So 23.03.2025 07:34
Betreff: Re: [std-proposals] #pragma once safer alternative
An: std-proposals@lists.isocpp.org;
CC: Muhammad <mail@muhamad.me>;
OK, let's revisit #include for a minute. When the compiler hit the #include directive it will add the content of that file in-place of that directive and then will recursively scan the content for other #include for expansion.
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals