Re: Portable check for unportable macro usage - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Portable check for unportable macro usage
Date
Msg-id 17554.1476898910@sss.pgh.pa.us
Whole thread Raw
In response to Re: Portable check for unportable macro usage  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
Andres Freund <andres@anarazel.de> writes:
> Hm. I'd be kind of inclined to instead do something akin to

> #include <ctype.h>
> #define system_isupper(c) isupper(c)
> #undef isupper

Note that that doesn't do what you are probably thinking it does.

What is actually happening there, I believe, is that you're forcing
a fallback to the plain-function definition of isupper().  Ralph's
proposal accomplishes the same thing less messily by parenthesizing
the new macro's reference to isupper.  But in either case, we're
disabling any possible macro optimization in <ctype.h>, which makes
me not want to say it's something we'd enable unconditionally.

> #define isupper(c) (AssertVariableIsOfTypeMacro(c, unsigned char), isupper(c))
> =>
> /home/andres/src/postgresql/src/include/c.h:745:7: error: static assertion failed: "c does not have type unsigned
char"

Not sure we really want that; it breaks the standard-intended usage
of applying these functions to the result of getc().  It might be
all right for the core code, but I could see third-party authors
getting pretty upset with us for unilaterally imposing non-POSIX
semantics on these functions.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: incorrect libpq comment
Next
From: Thom Brown
Date:
Subject: Re: Patch: Implement failover on libpq connect level.