I'm working my way through some old cross-platform C code. The code uses a number of variables defined like this:
complex double *cur; /* Amplitude of basis function */
This line compiles fine on OSX and iOS, but in VS I get two errors:
invalid combination of type specifiers
appears on the "double". I suspect this is not really an error and the real problem is:
identifier _complex is undefined
which appears on the word "complex". When I right-click and get the definition, I go to math.h
as I would expect, and find this definition:
#ifndef _COMPLEX_DEFINED
#define _COMPLEX_DEFINED
struct _complex
{
double x, y; // real and imaginary parts
};
#if !__STDC__ && !defined __cplusplus
// Non-ANSI name for compatibility
#define complex _complex
#endif
#endif
The thing I don't get is how does it even recognize complex
as an alias for _complex
if this code didn't work properly?
Poking about here on SO I found this thread. It suggests using _Dcomplex
from complex.h
for these variables. Is that correct? If so, what is this complex
in math.h
?
In any event, this code has to be cross-platform. Is there a way I can #define a way for this to work on VS as well as other systems?