[Cfp-interest] tgmath and macro suppression

Jim Thomas jaswthomas at sbcglobal.net
Fri Mar 23 17:48:01 PDT 2012


On Mar 23, 2012, at 5:32 AM, Joel C. Salomon wrote:

> 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.

Please explain this in more detail. 

> 
> 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.

Are you referring to the definition in 7.25? I don't recall that being the intention.

-Jim


> 
> (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