Error compiling complex.h with c++ (GCC 4.8.1)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Error compiling complex.h with c++ (GCC 4.8.1)

chivin90
I wrote code for complex numbers using include file <Mingw /include
/complex.h> . When I compile the file

>> gcc test.c -o test.exe
works correctly. However, when I compile another file <fft.c> where by
>> c ++ -o fft.c fft.exe
I have the following error:

fft.c:420:23: error: ISO c++ forbids declaration of declaration of 'make_cv'
with no type [-fpermissive]
   complex* make_cv(int n){

fft.c: In function '__complex__' int* make_cv(int)':
ftt.c:421:20:error: ISO C++ forbids declaration of 'type name' with no type
[-fpermissive]
   return (complex*)malloc(sizeof(complex)*n);

fft.c: 16:17: error: ISO C++ forbids declaration of 'type name'  with no
type[-fpermissive]
   #define complex _Complex

fft.c:421:38: note: in expansion of macro 'complex'
   return (complex*) malloc(sizeof(complex)*n);

The source code of the function is as follows
#ifndef complex
#define complex _Complex
#endif
complex* make_cv(int n) {
    return (complex*) malloc(sizeof (complex) * n);
}

I am using c++ (GCC 4.8.1).

Chivin



--
View this message in context: http://mingw.5.n7.nabble.com/Error-compiling-complex-h-with-c-GCC-4-8-1-tp34028.html
Sent from the MinGW - User mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Error compiling complex.h with c++ (GCC 4.8.1)

Keith Marshall
On 11/11/14 22:56, chivin90 wrote:
> I wrote code for complex numbers using include file <Mingw /include
> /complex.h> . When I compile the file
>
>>> gcc test.c -o test.exe
> works correctly. However, when I compile another file <fft.c> where by
>>> c ++ -o fft.c fft.exe

I presume this is a typo, and that you actually mean:

  g++ -o fft.exe fft.c

> I have the following error:
>
> fft.c:420:23: error: ISO c++ forbids declaration of declaration of 'make_cv'
> with no type [-fpermissive]
>    complex* make_cv(int n){
>
> [...snip similar diagnostics...]

FWIW, this isn't peculiar to MinGW; see below...

> The source code of the function is as follows
> #ifndef complex
> #define complex _Complex
> #endif
> complex* make_cv(int n) {
>     return (complex*) malloc(sizeof (complex) * n);
> }

You should provide such examples in the SSCCE form[*]; unfortunately,
while it's close, this isn't quite complete.

[*]: http://sscce.org/

> I am using c++ (GCC 4.8.1).

After adding the two missing includes, to complete your example, I can
reproduce this with my GCC 4.8.2 mingw32-g++ cross compiler, and also
with the native (Debian 4.8.2-2) g++ on the Linux host.

I don't have a definitive answer for you -- I would probably still
choose FORTRAN for complex number crunching -- but it would seem that
C99 and C++98 complex number handling, (substantially unchanged in
C++11, AIUI), may be mutually incompatible; (IOW, if you are writing
C++, use C++ complex classes, not the C99 provisions of complex.h).  You
may get a more definitive answer, if you ask on the GCC list, or in one
of the more generalized C/C++ programming fora; if you do so, please
report any final outcome back here, just to complete this thread.

--
Regards,
Keith.

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Error compiling complex.h with c++ (GCC 4.8.1)

Keith Marshall
On 12/11/14 09:37, Keith Marshall wrote:
> with the native (Debian 4.8.2-2) g++ on the Linux host.

Correction: that should be Debian 4.8.2-1

--
Regards,
Keith.

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Error compiling complex.h with c++ (GCC 4.8.1)

Keith Marshall
In reply to this post by Keith Marshall
On 12/11/14 09:37, Keith Marshall wrote:
> On 11/11/14 22:56, chivin90 wrote:
>> I wrote code for complex numbers using include file <Mingw /include
>> /complex.h> . When I compile the file
>> [...snip...]

>> I have the following error:
>>
>> fft.c:420:23: error: ISO c++ forbids declaration of declaration of 'make_cv'
>> with no type [-fpermissive]
>>    complex* make_cv(int n){
>>
>> [...snip similar diagnostics...]
>
> FWIW, this isn't peculiar to MinGW; ...

...but, on closer examination, I think it's actually your misuse of the
complex number features, because...

>> The source code of the function is as follows
>> #ifndef complex
>> #define complex _Complex
>> #endif

In complex.h, this define is *explicitly* *excluded* when compiling as
C++; if you are compiling with g++, you should *not* define this!

>> complex* make_cv(int n) {
>>     return (complex*) malloc(sizeof (complex) * n);
>> }

And here is the real culprit.  You are using 'complex' as if it were a
data type, but it is no such thing ... it is merely a type qualifier.
You are defining make_cv() without a type, which is allowed in C, (it
defaults to 'int', which in this case is qualified to become 'complex
int').  Default typing, such as this, is expressly forbidden in C++;
hence your error.  You *must* explicitly identify the function return type:

  complex int make_cv(int n)

and similarly, in the subsequent cast, and sizeof() evaluation:

  return (complex int*) malloc(sizeof (complex int) * n);

FWIW, that sizeof() evaluation multiplied by 'n' also looks suspect.
However, I don't know what the objective of make_cv() is; perhaps you
really are just asking it to allocate storage for an array of 'n'
uninitialized complex ints.

--
Regards,
Keith.

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe