473,378 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

_Complex constant

Is there any way to create a constant of type double _Complex without
including <complex.h>?

Why _Complex_I is a macro an not an implementation-defined constant?

Thanks.

a+, ld.
Nov 23 '06 #1
22 5938
Laurent Deniau wrote:
Is there any way to create a constant of type double _Complex without
including <complex.h>?
>From the C99 rationale:
"An I suffix to designate imaginary constants is not required, as
multiplication by I provides a sufficiently convenient and more
generally useful notation for imaginary terms."

So unless you count implementation-specific extensions, or complex
constants with an imaginary part of zero, then no, probably not.
Why _Complex_I is a macro an not an implementation-defined constant?
Constants can't be used in constant expressions.

#include <complex.h>
const double complex i = I; /* or equivalently, _Complex_I */
double complex v = 1 + 2 * i; /* error: initializer element is not
constant */

Nov 23 '06 #2
Harald van Dijk wrote:
Laurent Deniau wrote:
>>Is there any way to create a constant of type double _Complex without
including <complex.h>?

>>From the C99 rationale:
"An I suffix to designate imaginary constants is not required, as
multiplication by I provides a sufficiently convenient and more
generally useful notation for imaginary terms."

So unless you count implementation-specific extensions, or complex
constants with an imaginary part of zero, then no, probably not.

>>Why _Complex_I is a macro an not an implementation-defined constant?


Constants can't be used in constant expressions.

#include <complex.h>
const double complex i = I; /* or equivalently, _Complex_I */
double complex v = 1 + 2 * i; /* error: initializer element is not
constant */
Right. By specifying 'implementation-defined constant' I was thinking to
a special constant like null pointer constant. Something that would
expand to a compiler constant like __builtin_Complex_I for example.

My problem is that even with complex.h included, gcc (4.1.2) gives a
warning in c99 pedantic mode for the code:

const double complex i = _Complex_I;

warning: imaginary constants are a GCC extension

in complex.h we find (as you mention it):

#define _Complex_I (__extension__ 1.0iF)

It seems that this warning is not appropriate, but gcc cannot know with
this definition. Any clue?

Thanks.

a+, ld.

Nov 23 '06 #3
Laurent Deniau wrote:
Harald van Dijk wrote:
Laurent Deniau wrote:
>Why _Complex_I is a macro an not an implementation-defined constant?
Constants can't be used in constant expressions.

Right. By specifying 'implementation-defined constant' I was thinking to
a special constant like null pointer constant. Something that would
expand to a compiler constant like __builtin_Complex_I for example.
Well, that's basically what _Complex_I is required to do already. (Not
explicitly by the standard, but I can't imagine how an implementation
would support it otherwise.) As you show below, GCC uses a compiler
constant itself.
My problem is that even with complex.h included, gcc (4.1.2) gives a
warning in c99 pedantic mode for the code:

const double complex i = _Complex_I;

warning: imaginary constants are a GCC extension

in complex.h we find (as you mention it):

#define _Complex_I (__extension__ 1.0iF)

It seems that this warning is not appropriate, but gcc cannot know with
this definition. Any clue?
That's a long-standing bug in GCC:
http://gcc.gnu.org/PR7263

There's not much else to do but either ignore the warning, or use a
different compiler.

Nov 23 '06 #4
"Harald van Dijk" <tr*****@gmail.comwrites:
Laurent Deniau wrote:
[...]
>Why _Complex_I is a macro an not an implementation-defined constant?

Constants can't be used in constant expressions.

#include <complex.h>
const double complex i = I; /* or equivalently, _Complex_I */
double complex v = 1 + 2 * i; /* error: initializer element is not
constant */
Constants can (e.g., 42 and 1.23 are constants); const-qualified
objects cannot.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 23 '06 #5
Keith Thompson wrote:
"Harald van Dijk" <tr*****@gmail.comwrites:
Laurent Deniau wrote:
[...]
Why _Complex_I is a macro an not an implementation-defined constant?
Constants can't be used in constant expressions.

#include <complex.h>
const double complex i = I; /* or equivalently, _Complex_I */
double complex v = 1 + 2 * i; /* error: initializer element is not
constant */

Constants can (e.g., 42 and 1.23 are constants); const-qualified
objects cannot.
Right, sorry, I (incorrectly) thought a different meaning of "constant"
was used.

Nov 23 '06 #6
"Harald van Dijk" <tr*****@gmail.comwrites:
Keith Thompson wrote:
>"Harald van Dijk" <tr*****@gmail.comwrites:
Laurent Deniau wrote:
[...]
>Why _Complex_I is a macro an not an implementation-defined constant?

Constants can't be used in constant expressions.

#include <complex.h>
const double complex i = I; /* or equivalently, _Complex_I */
double complex v = 1 + 2 * i; /* error: initializer element is not
constant */

Constants can (e.g., 42 and 1.23 are constants); const-qualified
objects cannot.

Right, sorry, I (incorrectly) thought a different meaning of "constant"
was used.
That's a very easy mistake to make, since "const" and "constant" mean
two very different things in C.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 23 '06 #7
Harald van Dijk wrote:
Laurent Deniau wrote:
>>It seems that this warning is not appropriate, but gcc cannot know with
this definition. Any clue?


That's a long-standing bug in GCC:
http://gcc.gnu.org/PR7263

There's not much else to do but either ignore the warning, or use a
different compiler.
It brings me to another question. I do a lot of calculation with complex
numbers (making the above warning painful unless I declare my own global
const-qualified _Complex_I) and up to now I was using my own complex
number lib (or gsl lib sometimes) mainly because I wanted the principal
branch of some functions to be compliant with matlab results. I am
planning to move my code to C99 _Complex, but is it widely supported and
conform to the standard by actual compilers? Do you know where I could
find any paper, link or document about comparison of compilers
compiliance to C99, including complex number? Or do think that it would
be wiser to stay with lib gsl for example?

Thanks,

a+, ld.

Nov 24 '06 #8
Laurent Deniau wrote:
Harald van Dijk wrote:
Laurent Deniau wrote:
>It seems that this warning is not appropriate, but gcc cannot know with
this definition. Any clue?

That's a long-standing bug in GCC:
http://gcc.gnu.org/PR7263

There's not much else to do but either ignore the warning, or use a
different compiler.

It brings me to another question. I do a lot of calculation with complex
numbers (making the above warning painful unless I declare my own global
const-qualified _Complex_I) and up to now I was using my own complex
number lib (or gsl lib sometimes) mainly because I wanted the principal
branch of some functions to be compliant with matlab results. I am
planning to move my code to C99 _Complex, but is it widely supported and
conform to the standard by actual compilers?
If you wish for your users to be able to compile your code (it sounds
as if you do), I'd first like to point out they don't need to compile
it with GCC's -pedantic option, so this is hardly a problem for them.
That said, ignoring GCC, Intel's and Sun's compilers claim to support
it, and for Windows platforms, lcc-win32 and Pelles C are likely to
support it (although I haven't tested this).
Do you know where I could
find any paper, link or document about comparison of compilers
compiliance to C99, including complex number?
No idea, sorry.
Or do think that it would
be wiser to stay with lib gsl for example?
That depends on your needs. I don't know what sort of code you've
written, but another possibility is to support both, and use only one
(with C99 support to be detected by your build process). This means
your code can be portable to C90 implementations, yet you don't
introduce needless incompatibilities between your own lib and C99's
standard library.

Nov 24 '06 #9
Harald van D?k wrote:
>
.... snip ...
>
If you wish for your users to be able to compile your code (it sounds
as if you do), I'd first like to point out they don't need to compile
it with GCC's -pedantic option, so this is hardly a problem for them.
That said, ignoring GCC, Intel's and Sun's compilers claim to support
it, and for Windows platforms, lcc-win32 and Pelles C are likely to
support it (although I haven't tested this).
On the contrary, without -ansi -pedantic gcc isn't a C compiler.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Nov 24 '06 #10
CBFalconer wrote:
Harald van D?k wrote:
... snip ...

If you wish for your users to be able to compile your code (it sounds
as if you do), I'd first like to point out they don't need to compile
it with GCC's -pedantic option, so this is hardly a problem for them.
That said, ignoring GCC, Intel's and Sun's compilers claim to support
it, and for Windows platforms, lcc-win32 and Pelles C are likely to
support it (although I haven't tested this).

On the contrary, without -ansi -pedantic gcc isn't a C compiler.
I'll pretend you said -std=c99 -pedantic, and that GCC with those
options conforms to C99. But the users don't need a conforming
compiler. They need a compiler that correctly translates conforming
programs. Without -pedantic, GCC accepts some invalid programs, but it
doesn't reject valid programs.

Nov 24 '06 #11
In article <45***************@yahoo.com>,
CBFalconer <cb********@maineline.netwrote:
>Harald van D?k wrote:
>>
... snip ...
>>
If you wish for your users to be able to compile your code (it sounds
as if you do), I'd first like to point out they don't need to compile
it with GCC's -pedantic option, so this is hardly a problem for them.
That said, ignoring GCC, Intel's and Sun's compilers claim to support
it, and for Windows platforms, lcc-win32 and Pelles C are likely to
support it (although I haven't tested this).

On the contrary, without -ansi -pedantic gcc isn't a C compiler.
It is hard to imagine a more dumb, stupid, and thoroughly incorrect
statement.

Nov 24 '06 #12
Harald van Dijk wrote:
That depends on your needs. I don't know what sort of code you've
written, but another possibility is to support both, and use only one
(with C99 support to be detected by your build process). This means
your code can be portable to C90 implementations, yet you don't
introduce needless incompatibilities between your own lib and C99's
standard library.
My code requires C99 anyway (a moderately compliant compiler) for many
reasons (variadic macros, compound litteral and long long are the most
important features I need). But it doesn't means that I should blindly
trust the compiler implementation, even if it claims to be C99 (at least
by the build process detection which cannot go on the compiler's web
site and the list of incomplete features ;-) . Since _Complex must be
have the same representation and alignment as double[2], some
alternative may exist that would solve part of the portability problem.

a+, ld.
Nov 24 '06 #13
Harald van D?k wrote:
CBFalconer wrote:
>Harald van D?k wrote:
>>>
... snip ...
>>>
If you wish for your users to be able to compile your code (it sounds
as if you do), I'd first like to point out they don't need to compile
it with GCC's -pedantic option, so this is hardly a problem for them.
That said, ignoring GCC, Intel's and Sun's compilers claim to support
it, and for Windows platforms, lcc-win32 and Pelles C are likely to
support it (although I haven't tested this).

On the contrary, without -ansi -pedantic gcc isn't a C compiler.

I'll pretend you said -std=c99 -pedantic, and that GCC with those
options conforms to C99. But the users don't need a conforming
compiler. They need a compiler that correctly translates conforming
programs. Without -pedantic, GCC accepts some invalid programs, but it
doesn't reject valid programs.
gcc with -c99 is neither fish nor fowl. It does not fully comply
with C99, especially when using a C90 library. With -ansi
-pedantic the user is at least warned that some constructs are not
portable and need to be isolated in a system dependant module.
Examples are the z printf modifier, variable arrays, and _Bool.
Also the use of // comments.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Nov 24 '06 #14
CBFalconer wrote:
gcc with -c99 is neither fish nor fowl. It does not fully comply
with C99, especially when using a C90 library. With -ansi
-pedantic the user is at least warned that some constructs are not
portable and need to be isolated in a system dependant module.
Examples are the z printf modifier, variable arrays, and _Bool.
Also the use of // comments.
Please explain to me the point of suggesting invoking gcc in
C90-conforming mode in a thread asking about _Complex.

Nov 25 '06 #15
Harald van D?k said:
CBFalconer wrote:
>gcc with -c99 is neither fish nor fowl. It does not fully comply
with C99, especially when using a C90 library. With -ansi
-pedantic the user is at least warned that some constructs are not
portable and need to be isolated in a system dependant module.
Examples are the z printf modifier, variable arrays, and _Bool.
Also the use of // comments.

Please explain to me the point of suggesting invoking gcc in
C90-conforming mode in a thread asking about _Complex.
Please explain to me the point of using gcc when clearly what is actually
needed, for _Complex to be considered anything other than an off-topic
extension, is a C99-conforming compiler (which gcc very definitely isn't).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 25 '06 #16
Richard Heathfield wrote:
Harald van D?k said:
CBFalconer wrote:
gcc with -c99 is neither fish nor fowl. It does not fully comply
with C99, especially when using a C90 library. With -ansi
-pedantic the user is at least warned that some constructs are not
portable and need to be isolated in a system dependant module.
Examples are the z printf modifier, variable arrays, and _Bool.
Also the use of // comments.
Please explain to me the point of suggesting invoking gcc in
C90-conforming mode in a thread asking about _Complex.

Please explain to me the point of using gcc when clearly what is actually
needed, for _Complex to be considered anything other than an off-topic
extension, is a C99-conforming compiler (which gcc very definitely isn't).
Yes, gcc is not a conforming compiler. However, code written in the
common subset of C99 and what gcc accepts is still on topic here.

Nov 25 '06 #17
Harald van D?k said:
Richard Heathfield wrote:
>Harald van D?k said:
CBFalconer wrote:
gcc with -c99 is neither fish nor fowl. It does not fully comply
with C99, especially when using a C90 library. With -ansi
-pedantic the user is at least warned that some constructs are not
portable and need to be isolated in a system dependant module.
Examples are the z printf modifier, variable arrays, and _Bool.
Also the use of // comments.

Please explain to me the point of suggesting invoking gcc in
C90-conforming mode in a thread asking about _Complex.

Please explain to me the point of using gcc when clearly what is actually
needed, for _Complex to be considered anything other than an off-topic
extension, is a C99-conforming compiler (which gcc very definitely
isn't).

Yes, gcc is not a conforming compiler. However, code written in the
common subset of C99 and what gcc accepts is still on topic here.
But _Complex is not within that common subset, because gcc does *not* claim
to provide complex or imaginary support in line with the requirements of
C99. See http://gcc.gnu.org/c99status.html if need be.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 25 '06 #18
Richard Heathfield wrote:
Harald van D?k said:
Yes, gcc is not a conforming compiler. However, code written in the
common subset of C99 and what gcc accepts is still on topic here.

But _Complex is not within that common subset, because gcc does *not* claim
to provide complex or imaginary support in line with the requirements of
C99. See http://gcc.gnu.org/c99status.html if need be.
That's a fair point, but what it proves is that there are *some*
(actually, very few) uses of _Complex that are outside of that common
subset, not that all uses of it are.

Nov 25 '06 #19
Harald van D?k said:
Richard Heathfield wrote:
>Harald van D?k said:
Yes, gcc is not a conforming compiler. However, code written in the
common subset of C99 and what gcc accepts is still on topic here.

But _Complex is not within that common subset, because gcc does *not*
claim to provide complex or imaginary support in line with the
requirements of C99. See http://gcc.gnu.org/c99status.html if need be.

That's a fair point, but what it proves is that there are *some*
(actually, very few) uses of _Complex that are outside of that common
subset, not that all uses of it are.
I think we've said all the right mantras now. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 25 '06 #20
Richard Heathfield wrote:
Harald van D?k said:
>Richard Heathfield wrote:
>>Harald van D?k said:

CBFalconer wrote:
gcc with -c99 is neither fish nor fowl. It does not fully comply
with C99, especially when using a C90 library. With -ansi
-pedantic the user is at least warned that some constructs are not
portable and need to be isolated in a system dependant module.
Examples are the z printf modifier, variable arrays, and _Bool.
Also the use of // comments.

Please explain to me the point of suggesting invoking gcc in
C90-conforming mode in a thread asking about _Complex.

Please explain to me the point of using gcc when clearly what is
actually needed, for _Complex to be considered anything other
than an off-topic extension, is a C99-conforming compiler (which
gcc very definitely isn't).

Yes, gcc is not a conforming compiler. However, code written in the
common subset of C99 and what gcc accepts is still on topic here.

But _Complex is not within that common subset, because gcc does
*not* claim to provide complex or imaginary support in line with the
requirements of C99. See http://gcc.gnu.org/c99status.html if need be.
and, when gcc becomes fully C99 compliant, the -ansi -pedantic
switches will access that.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Nov 25 '06 #21
CBFalconer <cb********@yahoo.comwrites:
Richard Heathfield wrote:
[...]
>But _Complex is not within that common subset, because gcc does
*not* claim to provide complex or imaginary support in line with the
requirements of C99. See http://gcc.gnu.org/c99status.html if need be.

and, when gcc becomes fully C99 compliant, the -ansi -pedantic
switches will access that.
<OT>
Actually, I'd expect "-ansi" to retain its current meaning
(conformance to the C89/C90 standard) indefinitely. It's equivalent
to "-std=c89", and it's likely to remain so. But if you want to be
sure of which standard you're asking it to support, "-std=c89" is more
specific and less likely to change.
</OT>

The C standard is more properly referred to as ISO rather than ANSI
anyway.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 27 '06 #22
Keith Thompson wrote:
CBFalconer <cb********@yahoo.comwrites:
>Richard Heathfield wrote:
[...]
>>But _Complex is not within that common subset, because gcc does
*not* claim to provide complex or imaginary support in line with the
requirements of C99. See http://gcc.gnu.org/c99status.html if need be.

and, when gcc becomes fully C99 compliant, the -ansi -pedantic
switches will access that.

<OT>
Actually, I'd expect "-ansi" to retain its current meaning
(conformance to the C89/C90 standard) indefinitely. It's equivalent
to "-std=c89", and it's likely to remain so. But if you want to be
sure of which standard you're asking it to support, "-std=c89" is more
specific and less likely to change.
</OT>
GNU has stated that they plan to do as I posted.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Nov 28 '06 #23

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

Similar topics

25
by: tsaar2003 | last post by:
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing...
3
by: lovecreatesbeauty | last post by:
Both `K&R C, 2nd' and `C: A reference manual, 5th' introduce the "hello, world" thing using the name "string-constant". But `ISO/IEC 9899:TC2' does not include this kind of thing in section `A.1.5...
25
by: galapogos | last post by:
Hi, I'm trying to compare an array of unsigned chars(basically just data without any context) with a constant, and I'm not sure how to do that. Say my array is array and I want to compare it with...
21
by: Lane Straatman | last post by:
#include <stdio.h> #include <stdlib.h> #include <complex.h> int main(void) { _Complex z1, z2, z3; z1 = .4 + .7i; z2 = pow(z1, 2); z3 = z1 * z1; printf("%f, %f \n", z1);
33
by: desktop | last post by:
In the C++ standard sec 23.1.2 table 69 it says that erase(q) where q is a pointer to an element can be done in amortized constant time. I guess that is not worst case since std::set is...
18
by: sinbad | last post by:
hi, why does the following program gives an runtime error ,instead of compilation error. anyone please shed some light. thanks sinbad ------------------------------ int main()
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.