简体   繁体   English

在g ++中使用std :: copysign

[英]Using std::copysign with g++

I just figured out some incompatibilities between my tested platforms using std::copysign. 我只是使用std :: copysign找出了测试平台之间的一些不兼容性。

At a first test I try in MSVC to get some algorithms tested. 在第一次测试中,我尝试在MSVC中测试一些算法。 Now I tried to port this c++(11) code to the Xilinx Zynq platform (A9+FPGA). 现在,我尝试将c ++(11)代码移植到Xilinx Zynq平台(A9 + FPGA)。

This is working so far except there is no std::copysign including cmath. 到目前为止,除了没有cmd的std :: copysign之外,这都可以工作。 So I have to use copysign without the namespace. 因此,我必须使用不带名称空间的copysign。

What would be the proper way of adding this function to the namespace? 将此功能添加到名称空间的正确方法是什么?

PS: I do not want to manage the same files on different platforms by hand just for namespace incompatibilities. PS:我不想仅出于命名空间不兼容性而在不同平台上手动管理相同文件。

Compile flag is: 编译标志为:

-c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -std=c++11

You could create a macro for msvc. 您可以为msvc创建一个宏。

#if defined(_MSC_VER) 
#define copysign std::copysign
#endif

However, c++11 should have the std namespace. 但是,c ++ 11应该具有std名称空间。 If you aren't compiling with c++11 enabled you might be getting a older set of libraries maybe? 如果您未使用启用的c ++ 11进行编译,则可能会得到一组较旧的库? I'd check to make sure that you are. 我会检查以确保您的身份。 If you can't compile with c++11 on your platform then the above should work. 如果您无法在自己的平台上使用c ++ 11进行编译,则上述方法应该可以使用。 Add more preprocessor flags to target more platforms if needed. 如果需要,添加更多预处理器标志以定位更多平台。

Another option is 另一种选择是

using namespace std;

which would cover both cases. 这将涵盖两种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM