C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Revising #pragma once

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 30 Aug 2024 07:01:53 -0700
On Thursday 29 August 2024 22:07:42 GMT-7 Tiago Freire via Std-Proposals
wrote:
> How do you prevent people from using the same macro for that include guard?

There's usually a 1:1 mapping between the include guard and the name that is
used for the #include line for anything that is included directly. For the
case of the indirect #include "utils.hpp", because it's known to be indirect,
developers already know to insert the path of the main include.

Because this ties "what you're trying to include" to "what gets included", the
result is almost all cases. And if another version of the same header is
somehow found due to broken/mixed build systems and vendored content
containing vendored content, like zlib.h, only one of them will be included
and one set of definitions will be present.

That may not be the correct file -- it might be the oldest. And resolving those
things can be a headache. But when they happen, they happen to whoever created
this build in the first place, be it the author of the project in question or
the integrator who integrated it into a larger one.

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

Received on 2024-08-30 14:01:58