This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Warning: imaginary constants are a GNU extension

Hello everyone,

I'm developing a code that involves complex number (complex.h).
In every line that has the imaginary I, such as:

float complex sum = 0.0 + 0.0*I;

or

noise[j][i] = conjf(eigen_vec[i][k] + eigen_vec[i+m-1][k]*I);

Keil gives that warning: " imaginary constants are a GNU extension".

In the complex.h has:

define I _Complex_I

Why is it giving that warning?
Is my code going to work properly?
How can I solve that warning?

Thanks in advanced.

Parents
  • The armcc doc says:

    In C99 mode, the compiler supports complex and imaginary numbers. In GNU mode, the compiler supports complex numbers only.

    The warning implies that you are running the compiler in GNU mode. If armcc says they support imaginary numbers in C99 mode, that could mean that they have support for _Imaginary_I; i.e. the macro I resolves to _Imaginary_I. You could try compiling with -std=c99. With this way, you can use the I macro without running into the warning, and no other workaround (like __extension__ or CMPLX) should be required.

    In your complex.h do you see _Imaginary_I macro defined?

    Edit: en.cppreference.com says that the macro CMPLX is based on _Imaginary_I, so you could even write it on your own, like so:

    #define CMPLX(x, y) ((double complex)((double)(x) + _Imaginary_I * (double)(y)))

    Similarly for CMPLXF and CMPLXL.

Reply
  • The armcc doc says:

    In C99 mode, the compiler supports complex and imaginary numbers. In GNU mode, the compiler supports complex numbers only.

    The warning implies that you are running the compiler in GNU mode. If armcc says they support imaginary numbers in C99 mode, that could mean that they have support for _Imaginary_I; i.e. the macro I resolves to _Imaginary_I. You could try compiling with -std=c99. With this way, you can use the I macro without running into the warning, and no other workaround (like __extension__ or CMPLX) should be required.

    In your complex.h do you see _Imaginary_I macro defined?

    Edit: en.cppreference.com says that the macro CMPLX is based on _Imaginary_I, so you could even write it on your own, like so:

    #define CMPLX(x, y) ((double complex)((double)(x) + _Imaginary_I * (double)(y)))

    Similarly for CMPLXF and CMPLXL.

Children