473,471 Members | 2,138 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Complex Style


According to my understanding of the standard, both of

_Complex double c1; (1)
double _Complex c2; (2)

should be syntactically correct and equivalent. Now, there's
been a recent thread here according to which (1) is not
accepted by at least one major compiler. On the other hand,
in existing code I'm working on I have almost exclusively
seen (1) and very rarely (2); gcc's documentation also uses
(1) and never (2).

Is my assumption above correct that both styles are legal
in strictly conforming code?

If yes, which style is preferable, seeing that not all
compilers implement both styles?

Jun 27 '08 #1
9 1393
Fumeur wrote, On 15/06/08 23:46:
According to my understanding of the standard, both of

_Complex double c1; (1)
double _Complex c2; (2)

should be syntactically correct and equivalent.
They are.
Now, there's
been a recent thread here according to which (1) is not
accepted by at least one major compiler.
Define major. I had never heard of the compiler in question (if it is
the one I suspect) until I joined this group. MSVC and gcc, on the other
hand, I was aware of.
On the other hand,
in existing code I'm working on I have almost exclusively
seen (1) and very rarely (2); gcc's documentation also uses
(1) and never (2).
So? Neither gcc documentation (specifically its example) nor examples in
the standard are proof of what is legal.
Is my assumption above correct that both styles are legal
in strictly conforming code?
They are both acceptable in a strictly conforming C99 program.
If yes, which style is preferable, seeing that not all
compilers implement both styles?
Personally I would use "_Complex double" (or maybe just "_Complex" if
that is legal) because to me it "sounds" better. If, however, programs
using _Complex tend to do it differently then I would switch to however
the majority did it for consistency.
--
Flash Gordon
Jun 27 '08 #2
Flash Gordon <sp**@flash-gordon.me.ukwrites:
Fumeur wrote, On 15/06/08 23:46:
>According to my understanding of the standard, both of
_Complex double c1; (1)
double _Complex c2; (2)
should be syntactically correct and equivalent.

They are.
> Now, there's been a recent thread here according to which (1) is
not accepted by at least one major compiler.

Define major. I had never heard of the compiler in question (if it is
the one I suspect) until I joined this group. MSVC and gcc, on the
other hand, I was aware of.
> On the other hand, in existing code I'm working on I have almost
exclusively seen (1) and very rarely (2); gcc's documentation also
uses (1) and never (2).

So? Neither gcc documentation (specifically its example) nor examples
in the standard are proof of what is legal.
The standard refers to "float _Complex", "double _Complex", and "long
double _Complex" in both 6.2.5 (types) and 6.7.2 (type specifiers).
Of course other orders are legal (including "double _Complex long if
you want to be especially perverse, but please don't).
>Is my assumption above correct that both styles are legal
in strictly conforming code?

They are both acceptable in a strictly conforming C99 program.
>If yes, which style is preferable, seeing that not all compilers
implement both styles?

Personally I would use "_Complex double" (or maybe just "_Complex" if
that is legal) because to me it "sounds" better. If, however, programs
using _Complex tend to do it differently then I would switch to
however the majority did it for consistency.
No, just "_Complex" is not legal. (An example in C99 6.7.8p24 has
complex c = 5 + 3 * I;
This was corrected in one of the Technical Corrigenda.)

I'd follow the standard's usage (and I don't know why gcc's
documentation doesn't) unless there was some particular reason not to,
such as consistency with existing code.

I'd also add "#include <complex.h>" and use "complex" rather than
"_Complex".

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #3
Fumeur wrote:
According to my understanding of the standard, both of

_Complex double c1; (1)
double _Complex c2; (2)

should be syntactically correct and equivalent. Now, there's
been a recent thread here according to which (1) is not
accepted by at least one major compiler.
Hey, I test the following code:
/*file name is complex.c*/
#include<stdio.h>
int main()
{
double _Complex a = 1.5;
_Complex double b = 1.6;
printf("%f\n", a);
printf("%f\n", b);
}
and compile it buy command
$gcc complex.c
Then execute ./a.out
the result is:
1.500000
1.600000
No error occurs.
^_^
Jun 27 '08 #4
Gestorm <zh********@126.comwrites:
Fumeur wrote:
>According to my understanding of the standard, both of

_Complex double c1; (1)
double _Complex c2; (2)

should be syntactically correct and equivalent. Now, there's
been a recent thread here according to which (1) is not
accepted by at least one major compiler.

Hey, I test the following code:
/*file name is complex.c*/
#include<stdio.h>
int main()
{
double _Complex a = 1.5;
_Complex double b = 1.6;
printf("%f\n", a);
printf("%f\n", b);
}
and compile it buy command
$gcc complex.c
Then execute ./a.out
the result is:
1.500000
1.600000
No error occurs.
gcc was not the "major compiler" in question, so this isn't
surprising.

But you're printing values of type double _Complex using a "%f"
format, which requires an argument of type double.

Here's a corrected version:

#include <stdio.h>
#include <complex.h>

int main(void)
{
double _Complex a = 1.5;
_Complex double b = 1.6;
printf("a = %f + %f*I\n", creal(a), cimag(a));
printf("b = %f + %f*I\n", creal(b), cimag(b));
return 0;
}

The output is:

a = 1.500000 + 0.000000*I
b = 1.600000 + 0.000000*I

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #5
Keith Thompson wrote, On 16/06/08 01:47:
Flash Gordon <sp**@flash-gordon.me.ukwrites:
>Fumeur wrote, On 15/06/08 23:46:
<snip>
>Personally I would use "_Complex double" (or maybe just "_Complex" if
that is legal) because to me it "sounds" better. If, however, programs
using _Complex tend to do it differently then I would switch to
however the majority did it for consistency.

No, just "_Complex" is not legal. (An example in C99 6.7.8p24 has
complex c = 5 + 3 * I;
This was corrected in one of the Technical Corrigenda.)

I'd follow the standard's usage (and I don't know why gcc's
documentation doesn't) unless there was some particular reason not to,
such as consistency with existing code.
Ah well, my preference is not strong, so I may well do the same if I
ever end up using the complex types. I can certainly see the advantage
of following the way the standard expresses it.
I'd also add "#include <complex.h>" and use "complex" rather than
"_Complex".
I may well also do that if I ever use the type.
--
Flash Gordon
Jun 27 '08 #6

"Fumeur" <f6@invalid.invalidschreef in bericht
news:54*******************@invalid.invalid...
>
According to my understanding of the standard, both of

_Complex double c1; (1)
double _Complex c2; (2)

should be syntactically correct and equivalent. Now, there's
been a recent thread here according to which (1) is not
accepted by at least one major compiler.
The world wants to know which compiler

Jun 27 '08 #7

On Mon, 16 Jun 2008 18:41:16 +0200, "Serve Lau" <ni***@qinqin.comwrote:
>
"Fumeur" <f6@invalid.invalidschreef in bericht
news:54*******************@invalid.invalid...
>>
According to my understanding of the standard, both of

_Complex double c1; (1)
double _Complex c2; (2)

should be syntactically correct and equivalent. Now, there's
been a recent thread here according to which (1) is not
accepted by at least one major compiler.

The world wants to know which compiler
Do your own research!

Jun 27 '08 #8

"Fumeur" <f6@invalid.invalidschreef in bericht
news:26*******************@invalid.invalid...
>
On Mon, 16 Jun 2008 18:41:16 +0200, "Serve Lau" <ni***@qinqin.comwrote:
>>The world wants to know which compiler

Do your own research!
*cry* never mind then, the world doesnt want to know that bad :P

Jun 27 '08 #9

On Mon, 16 Jun 2008 23:48:17 +0200, "Serve Lau" <ni***@qinqin.comwrote:
>
"Fumeur" <f6@invalid.invalidschreef in bericht
news:26*******************@invalid.invalid...
>>
On Mon, 16 Jun 2008 18:41:16 +0200, "Serve Lau" <ni***@qinqin.comwrote:
>>>The world wants to know which compiler

Do your own research!

*cry* never mind then, the world doesnt want to know that bad :P
After reading back through the archives, I think "the world" really
may not know because the fact first popped up buried deeply inside
one of those homework threads.

The relevant article is "<ud************@localhost.invalid>" wherein
a C.L.C reader posted a piece of code using (among others) these two
type specifications:

_Complex double (1)

and

double _Complex (2)

In a followup article, "<31****************@aioe.org>", another
reader presented the compiler diagnostics he got on the line(s)
containing (1).

(being mainly a gcc user, I was a bit surprised by that...)

Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: burdeen | last post by:
I've been trying to return an array with PHP5 soap. Is this not supported? or am i doing it wrong? Seems to return on the last element in the array. In my WSDL i've defined my return type as a...
0
by: mjcsfo | last post by:
I can't seem to find a reference nor any helpful threads on this topic. I've gotten the following error in two circumstances: 1. A complex type has nested within it another complex type, in the...
5
by: bluesrift | last post by:
Using the WYSIWYG contenteditable feature, Internet Explorer will often add a style to the image tag to define its display size after the image has been dragged to display at something other than...
1
by: louis_la_brocante | last post by:
Dear all, I am having trouble generating a client proxy for a webservice whose methods return a "complex" type. The type is complex in that it is a class whose members are a mix of primitive...
9
by: Greg Buchholz | last post by:
/* While writing a C++ version of the Mandelbrot benchmark over at the "The Great Computer Language Shootout"... http://shootout.alioth.debian.org/gp4/benchmark.php?test=mandelbrot&lang=all ...
4
SHOverine
by: SHOverine | last post by:
I have a 3-part form that I am having trouble with. First part is to select the user group and the week and year that I want to submit results for, this calls the elements that I want to update. ...
0
by: scriptyasin | last post by:
Hi, I am a beginner in XSL processing. I have a xml which contains both text & subelements. Please find the XML below. Is it possible to transform the below XML as : "It is all...
1
by: perroe | last post by:
Hi I have a array of complex numbers that are stored in a simple double array. This is done since the array is part of an wrapper for an external C library, and the imaginary part of the first...
25
by: jacob navia | last post by:
The C99 standard forgot to define the printf equivalent for complex numbers Since I am revising the lcc-win implementation of complex numbers I decided to fill this hole with "Z" for...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.