Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c++
Subject: Re: Don't be fooled by cpp.sh
Date: Fri, 10 Jan 2020 14:51:54 -0800
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <86blra53hx.fsf@linuxsc.com>
References: <9j851fhqe4focdnq2uie27brr8n7icpj2h@4ax.com> <87d0bxmc3o.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="7b070c0766e341d0df2bb5814a4c869f"; logging-data="25914"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nHc2VT6AbCuPlX/SbCBn+RdCTxmfvq4g="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:7tbewyYHJus9j+SJmEyZR5r1cFQ= sha1:oSrN7R4k7ZKlZnrWtSAfFoKMyWc=
Xref: csiph.com comp.lang.c++:71269
Robert Wessel writes:
> On Sun, 05 Jan 2020 20:40:27 -0800, Keith Thompson
> wrote:
>
>> Robert Wessel writes:
>>
>>> On Sun, 5 Jan 2020 20:11:17 +0100, David Brown
>>> wrote:
>>
>> [...]
>>
>>>> I really don't understand why these were made optional in C11. Who is
>>>> going to make a compiler that is C11 compliant but not C99 compliant?
>>>> Who is going to be capable of making a C11 compiler but find supporting
>>>> VLA's or complex numbers a major issue?
>>>
>>> My point exactly. I don't even understand why complex was optional in
>>> C99 for freestanding implementations.
>>
>> Freestanding implementations don't have to provide library functions,
>> and complex numbers aren't very useful without the functions declared in
>> such as creal() and cimag().
>
> I've never really considered "no library" to really be a rule for
> freestanding implementations (certainly C++ hasn't followed that
> route). "Minimal" or "trivial" library, probably.
>
> Or you implement creal and cimag as macros (implementation dependent,
> but trivial, in most cases).
These functions can be done completely portably for any implementation
that has _Complex. Here are the 'double' versions:
double
creal( _Complex double z ){
return (union { _Complex double z; double dd[2]; }){ z }.dd[0];
}
double
cimag( _Complex double z ){
return (union { _Complex double z; double dd[2]; }){ z }.dd[1];
}