Hello, Am Dienstag, den 02.12.2014, 17:47 -0500 schrieb Rich Felker: > On Tue, Dec 02, 2014 at 11:00:12PM +0100, Jens Gustedt wrote: > Then what about something like > > #if __clang__ // && __clang_major__*100+__clang_minor__ <= xxxxx > // use clang compound literal hack > #elif __GNUC__*100+__GNUC_MINOR__ >= 407 > // use __builtin_complex > #else > // use _Complex_I with mult and add > #endif > > or alternatively: > > #if __clang__ // && __clang_major__*100+__clang_minor__ <= xxxxx > // use clang compound literal hack > #else > // use __builtin_complex > #endif > > I somewhat prefer the latter since the _Complex_I form is never really > correct (INF/NAN issues) and it gives better fallback behavior > assuming other compilers will implement __builtin_complex but might > not identify themselves as "GNU C >= 4.7". It also produces an error > on compilers that can't give the right behavior for INF/NAN rather > than silently miscompiling the code. I agree with your analysis, we should avoid using _Complex_I, here. For the implementation I don't agree completely. Version number games are not the right thing for clang, they don't support this, in a sense in the same way that you don't want a macro that identifies musl. They have their feature/builtin test framework, we should use that. This then would kick in whenever they decide to implement that builtin. But still, I'd like to have a version with _Imaginary_I, see below. > > > > > _Imaginary_I > > > > > is not supported yet at all and would require further changes to this > > > > > header to add anyway (this header is responsible for defining it), so > > > > > conditioning on its definition is not meaningful. > > > > > > > > I am not sure of that. It could also come directly from the compiler > > > > just as it defines some __SOMETHING__ macros before any include > > > > > > I don't think so. Consider: > > > > > > #undef _Imaginary_I > > > #include > > > > > > Perhaps this is non-conforming for technical reasons, > > > > it is non-conforming > > Because of the _-prefixed namespace? Yes, an implementation simply *mustn't* touch any identifier that starts with underscore and capital letter. Period. > Per my understanding, it's > conforming to #undef macros provided by the standard headers in many > cases. > Eliminating a function-like macro to get at the underlying > function is one such usage mentioned in the standard, but I think > there are others too. I don't know of many, and these are explicitly named. And all of this is *not* the same thing as the case above. This concerns e.g "complex" and "I" which are otherwise not reserved, and not e.g "_Complex_I" that falls under the same rule as _Imaginary_I. > > But if you want to avoid that branch, I understand. _Imaginary_I would > > be *the* way to solve all of this easily, sigh. > > Yes, I really wish GCC would support it, especially since Annex G > _requires_ _Imaginary_I, and glibc falsely advertises Annex G support > via the __STDC_IEC_559_COMPLEX__ macro despite not having > _Imaginary_I. But the glibc folks seem to think this is a non-issue > and I haven't seen any interest in fixing it on the GCC side. argh, I wasn't aware of that, what a mess. yes _Imaginary and all that comes with it is really an important feature of that Annex, e.g functions returning _Imaginary values when known to have such values. So I keep my claim for a first case version with _Imaginary_I up :) we should encourage compiler implementors to provide this feature. I looked a bit around and I found that - Keil supports imaginary - for Cray compilers 1.0i is pure imaginary and not complex, but they don't explain exactly what happens if you use this in arithmetic Jens -- :: INRIA Nancy Grand Est ::: AlGorille ::: ICube/ICPS ::: :: ::::::::::::::: office Strasbourg : +33 368854536 :: :: :::::::::::::::::::::: gsm France : +33 651400183 :: :: ::::::::::::::: gsm international : +49 15737185122 :: :: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::