delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/12/13/08:29:20

Message-ID: <001e01c06508$a04b3140$799a7ed4@oemcomputer>
From: "Stephen Silver" <djgpp AT argentum DOT freeserve DOT co DOT uk>
To: <djgpp-workers AT delorie DOT com>
Subject: Re: ctype.h in C++
Date: Wed, 13 Dec 2000 13:28:46 -0000
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Reply-To: djgpp-workers AT delorie DOT com

Eli Zaretskii wrote:

>> There is a problem with the ctype.h header when used in C++: all 13
>> standard functions are defined as macros, which is permissible in C, but
>> not in C++.
>> In particular, the compiler chokes on expressions such as
>> std::tolower('A') because a namespace qualifier cannot be applied to a
>> macro.
>
>Then why doesn't the C++ compiler disable the macros in its <ctype>
>(or is it <cctype>?) header?

At the moment, the <cctype> supplied with DJGPP just #includes <ctype.h>.
Disabling the macros in <cctype> would cause the non-inline versions
of these functions to be used, so it's not an ideal solution.  And it
wouldn't work at all if <ctype.h> is used directly (which is allowed in
C++, although the <*.h> headers are deprecated).

>Is the above the only problem with those macros, or are there
>additional circumstances where macros don't work.

This is the only case where I've had a problem with the macros.
In theory, there's also the problem that macros pollute the global
namespace, whereas everything in <cctype> ought to be confined to
namespace std.  But this doesn't matter much at the moment, since
the C++ header files erroneously dump everything into the global
namespace anyway.

>(You seem to be saying that C++ disallows ctype macros everywhere.)

Yes.  The C++ standard states this most clearly in footnote 159:

    This disallows the practice, allowed in C, of providing a
    "masking macro" in addition to the function prototype.  The only
    way to achieve equivalent "inline" behavior in C++ is to provide
    a definition as an extern inline function.

There may be other DJGPP header files where this is a problem - ctype.h
just happens to be the only one that stops my code compiling.

>Also, do the current versions of GCC even support the std namespace
>like that?

Yes, they just ignore std:: completely (except that they do check that
it's syntactically correct, which is why there's a problem with macros).

>I wonder how come we never heard such complaints until now?

I've noticed a widespread tendency for people to assume that since
GCC ignores std, they don't need to use it.  And there are simple
work-arounds to the problem, so even people who have noticed the
problem may not have bothered to report it.  Nonetheless, the DJGPP
ctype.h is wrong and ought to be fixed.

Stephen

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019