C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 23 Mar 2025 20:26:31 -0700
On Sunday, 23 March 2025 18:51:10 Pacific Daylight Time Muhammad via Std-
Proposals wrote:
> 5) Wait, isn't that behavior mostly how the #pragma once is working, and
> if so what benefit from adding this #include once?
> Yes and no. Yes in the essence of marking the file for no more
> inclusion, and No in how it is implemented.
> The #include once like other parts of the #include rules don't go on HOW
> the implementation should do it, but rather WHAT is the expected outcome
> from it.
>
> The benefit come from adding such directive:
> 1) pragma is compiler specific and cannot be standardized.
> 2) it is a unified way to "include a header once" with minimal change to
> the standard (the parts to update mostly in [lex.phases] and
> [cpp.include] as well as the grammer).
> 3) it shall not break existing implementations, the general rules
> discussed here already implemented by major compilers (Clang, GCC and
> MSVC).
>
> Hopefully this address the questions asked.

No, it did not.

The two major sticking points are still left unanswered:

One: you're not standardising behaviour. You're declaring that it suffices to
standardise the expected outcome but not dictate how to achieve that, but
reality is that compilers have different implementations and have had
incompatibility arise. If you're going to leave the incompatibilities allowed,
what's the point of standardising in the first place?

Second, if incompatibility is allowed anyway, then what's the advantage of
this over #pragma once. The latter exists and the most likely outcome is that
compilers would implement the exact same rules, which means the two token
sequences would perform exactly identically. So why do we need two?

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-03-24 03:26:37