#pragma is a compiler-specific and even #pragma once is implement by all major compilers, still it is not a standard way to go. so by preserving the pp-token once for usage by #include it will become reliable that any compiler will implement will implement it and this way we will rely on a standard behavior rather than a compiler-specific once. that what I mean by "safer".


------ Original Message ------
From "Andre Kostur" <andre@kostur.net>
To std-proposals@lists.isocpp.org
Cc "Muhammad" <mail@muhamad.me>
Date 3/23/2025 6:19:03 AM
Subject Re: [std-proposals] #pragma once safer alternative

How is this any “safer” than #pragma once?  What does “safer” mean in this context?

On Sat, Mar 22, 2025 at 21:16 Muhammad via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
The #include syntax (from cppreference.com)
  1. # include < h-char-sequence > new-line
  2. # include " h-char-sequence " new-line
  3. # include pp-tokens new-line
The pp-tokens in (3) is a macro that get expanded until it matches (1) or (2), and when it doesn't it is undefined behavior.

This proposal is to add another syntax for #include

  1. # include < h-char-sequence > new-line
  2. # include " h-char-sequence " new-line
  3. # include once new-line
  4. # include pp-tokens new-line

The fact that by convention all macros are written in all uppercase pr starts with underscore make this proposal very unlikely to break existing code.

The implementation for this proposal is already done using the compiler-specific #pragma once syntax but here it will be more convenient and a standard way to not include it more than once.
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals