[Cfp-interest] tgmath and macro suppression

Joel C. Salomon joelcsalomon at gmail.com
Fri Mar 23 05:32:29 PDT 2012


Jim Thomas <jaswthomas at sbcglobal.net> wrote:
> On Mar 22, 2012, at 5:09 PM, Joel C. Salomon wrote:
>> Jim Thomas <jaswthomas at sbcglobal.net> wrote:
>>> C11 doesn’t say what effect macro suppression has on the non-double
>>> functions invoked by tgmath. I think macro suppression should happen if and
>>> only if the program suppresses macro replacement for the function.
>>
>> If that were the case, this would be cause for a rather severe defect
>> report, given that <tgmath.h> is supposed to be implementable by mans
>> of the _Generic keyword.
>>
>> E.g., ignoring long doubles, within <tgmath.h> exp() will be defined
>> something like this:
>>
>>    #define exp(x) _Generic((x), float:expf, default:exp)(x)
>
> What if, instead, it were
>
>   #define exp(x) _Generic((x), float:expf(x), default:exp(x))
>
> (I realize this isn't what C11 suggests.)

That would be subject to macro expansion of expf()—in fact, there
would be no way to avoid this expansion—but not secondary expansion of
exp(), leading to an inconsistency.

I'd suggest that the definition of type-generic macros given is
implicitly intended to suppress macro expansion of expf() et al.
within the <tgmath.h> functions.

(Aside: I wonder if there hasn't been more discussion of <tgmath.h> &
_Generic on this list than anywhere else.)

—Joel



More information about the Cfp-interest mailing list