我正在擴展一個項目,它用c99編譯一些庫,用C++ 11編譯一個庫,並在c99庫中使用complex.h複數。如何用C++編譯c複數11
我知道這可能是一個愚蠢的想法,但它不是我的,我需要使它以某種方式工作。
該代碼不能用gcc4.9和-std = C++ 11進行編譯,而且我完全不知道該怎麼做。我如何編寫此代碼段?
#include <complex.h>
#include <cstdio>
int main(int argc, char * argv[]) {
double _Complex a = 3.0 + 0.0 * _Complex_I;
//printf("%lf\n", creal(a));
return 0;
}
給出了錯誤
In file included from /usr/local/include/c++/7.1.0/complex.h:36:0,
from main.cpp:1:
main.cpp: In function 'int main(int, char**)':
main.cpp:5:33: error: unable to find numeric literal operator 'operator""iF'
double _Complex a = 3.0 + 0.0 _Complex_I;
^
main.cpp:5:33: note: use -std=gnu++11 or -fext-numeric-literals to enable more built-in suffixes
main.cpp:5:33: error: expression cannot be used as a function
double _Complex a = 3.0 + 0.0 _Complex_I;
^
main.cpp:5:19: warning: unused variable 'a' [-Wunused-variable]
double _Complex a = 3.0 + 0.0 _Complex_I;
與
g++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out
-std = GNU ++ 11件作品看起來,但有沒有辦法讓它與-std = C工作++ 11?
不應該是'雙複雜a = 3.0 + 0.0 * _Complex_I;'? (注意'*') –
沒錯。我糾正了它 – Philipp