[vox-tech] C99 - Initializing complex

Micah J. Cowan micah at cowan.name
Mon Sep 6 15:36:08 PDT 2004


On Mon, Sep 06, 2004 at 06:12:47PM -0400, Peter Jay Salzman wrote:
> Must both parts of a complex variable be initialized:
> 
>    long double complex z = 0.0L + 0.0L*I;           (i)
> 
> or does only one part need to be initialized?
> 
>    long double complex z = 0.0L;                    (ii)
> 
> A test program shows that (ii) "works", but I couldn't find an authoritative
> answer in the C99 standard.  Although I have no intention of using anything
> but Linux, I still don't want to rely on GNU extensions (as much as
> possible).

The following paragraph winds a bit, but the most important bit is the
final sentence.

6.7.8#11 says that "the same type constraints and conversions as for
simple assignment apply...". In 6.5.16.1#1 (Simple Assignment:
Constraints), the applicable constraint that your (ii) fulfills is
that both operands must be arithmetic type (so now so far we are
guaranteed at least that a diagnostic has not been required). 6.7.8#11
states that the initial value of the declared object will be the value
of the initializer, after conversion; and 6.3.1.7#1 states that the
value of a complex object converted from a real is such that its real
part has the (converted) value of the real from which it was
converted, and the imaginary part is zero.

> BTW, my copy of the C99 standard is from August 3, 1998 and appears to be a
> "pre-release".  I'm a little surprised that a Google search for "C99
> standard" just doesn't give a copy of the standard the way a Google search
> for "US Constitution" yields the Constitution.  Where is the official copy of
> this standard?

webstore.ansi.org has it (ANSI being a member of the ISO). C99 is a
nickname: the language is still "The C Programming Language": the
official designation is ISO/IEC 9899:1999.

-- 
Micah J. Cowan
micah at cowan.name


More information about the vox-tech mailing list