On Wednesday, May 15, 2019 at 10:40:11 AM UTC-3, Öö Tiib wrote:
...
> I am still skewed towards defining NOMINMAX either as
> default command line option or before including windows.h
> in that stdafx.h or pch.h or whatever it is. It will be less to
> type than those pragmas (or calls of metaprogramming
> macros) and more pleasant for eye to read. Kind of done
> once and then forgotten forever with works(TM).
I put the sample of windows.h min/max just as reference.
I am not worried about this specific case.
At the #scope proposal pdf (A simple scoping mechanism for
the C/C++ preprocessor) we can find more motivation at 'the
problem' section.
"
The problem
We need to protect code, especially code in header files, from
accidental matches of macros. The basic traditional defense is to
define all macros as ALL_CAPS and never define other identifiers
with all capital letters. Unfortunately, in much code not all macros
are ALL_CAPS and some identifiers (notably some enumerators and some
consts) are defined using all capital letters (and thus especially
vulnerable to macro substitution). All useful programs must use
headers, but we cannot control how macros are defined in headers
nor can a writer of a header control how an #includeing program
use identifiers.
Therefore, “house style rules” cannot in general prevent accidents,
and errors are common.
These problems are well known and partially effective remedies
are widely adopted. However, there is a huge variety in the kind
of remedies adopted and the degree to which they are systematically
applied. In all cases, the result is defensively written code
that to various degrees departs from the ideal expression of the
ideas it represents.
The seriousness of this problem increases with the number of macros used,
the number of headers included, and the number of independent sources
of headers. Most large organizations – even quite mature and experienced
ones – are regularly “bitten” by macro.
"
The main point for me is:
"Unfortunately, in much code not all macros
are ALL_CAPS and some identifiers (notably some enumerators and some
consts) are defined using all capital letters (and thus especially
vulnerable to macro substitution). All useful programs must use
headers, but we cannot control how macros are defined in headers
nor can a writer of a header control how an #includeing program
use identifiers. "
for C++, modules will help this I guess.