编译器中是否有任何标志仅预编译 IPV6
我已经使用标志设置编写了 IPv6 实现的代码。如果我需要启用 IPv6 部分,则需要在编译过程之前在头文件中设置该标志。编译器本身是否提供了任何标志,以便我只需要使用语句 #ifdef COMPILER_FLAG_FOR_IPV6 来启用代码的 IPv6 部分。如果没有,则编译 IPv4 部分。我不想在这里手动定义标志,而是使用 IPV6 的内置标志。
I have written the code for IPv6 implementation using a flag setting. The flag needs to be set in the header file before the compilation process if I need to enable IPv6 part. Is there any flag provided with the compiler itself so that I just need to use the statement #ifdef COMPILER_FLAG_FOR_IPV6 to enable IPv6 part of code. If not then IPv4 part is compiled. I dont want to manually define a flag here rather use a inbuilt flag for IPV6.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IPv6 兼容性不依赖于编译器支持,而是依赖于操作系统特定的头文件。没有标准的方法来测试这一点。 (正如所指出的,您可能希望 CMake/AutoConf/其他一些构建系统来检测这一点)。
您还可以更直接地实现您似乎正在寻找的目标,例如在 Linux 上您可能可以这样做:
我不确定我想打赌它的便携性/可靠性如何,但我猜它会起作用使用
sys/socket.h
的任何实现并快速浏览winsock2.h
似乎有类似的#define
的AF_INET6也是。
IPv6 compatibility is not dependent upon compiler support, rather OS-specific header files. There is no standard way of testing this as such. (As was pointed out you'd probably want CMake/AutoConf/Some other build system to detect this).
You can also achieve what you seem to be looking for more directly, on Linux for example you can probably do:
I'm not sure I'd want to bet on how portable/reliable this is though, I'd guess it would work with any implementation of
sys/socket.h
and a quick look throughwinsock2.h
seems to have a similar#define
ofAF_INET6
too.