error C2265: '<Unknown>' : reference to a zero-sized array is illegal

来源:互联网 发布:java连接cassandra 编辑:程序博客网 时间:2024/06/08 16:36

前言
今天要总结知识点, setsockopt and UDP_NOCHECKSUM, 突然发现编译不过.
在网上查了下解决方法, 自己分析了一下,人家为什么那么改. 学学人家分析解决问题的路子.
测试代码

// testcase.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <stdlib.h>#include <stdio.h>#define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers#define _WIN32_WINNT 0x501 ///< if no this, error below/**\program files (x86)\microsoft visual studio\vc98\include\wspiapi.h(45) : error C2265: '<Unknown>' : reference to a zero-sized array is illegal*/#include <winsock2.h>#pragma comment(lib, "Ws2_32.lib")#include <windows.h>#include <Ws2tcpip.h> ///< 如果没定义 #define _WIN32_WINNT 0x501, 加了这个.h后报错/// Ws2tcpip.h的位置在 \Program Files (x86)\Microsoft Visual Studio\VC98\Include/// 去Ws2tcpip.h中看包含wspiapi.h的代码如下/**//// Unless the build environment is explicitly targeting only// platforms that include built-in getaddrinfo() support, include// the backwards-compatibility version of the relevant APIs.//#if !defined(_WIN32_WINNT) || (_WIN32_WINNT <= 0x0500)#include <wspiapi.h>#endif*//// 可以看出 只要_WIN32_WINNT > 0x500就可以不包含这个引起报错的头文件/// 这就是要定义 #define _WIN32_WINNT 0x501 的原因/// 从M$的注释看, wspiapi.h是为了兼容低版本Windows用的, /// 如果Widnows版本较高可以不包含此头文件/**win7 _WIN32_WINNT>=0x0601vista _WIN32_WINNT>=0x0600Windows   XP _WIN32_WINNT>=0x0501     Windows   2000 _WIN32_WINNT>=0x0500     Windows   NT   4.0 _WIN32_WINNT>=0x0400     Windows   Me _WIN32_WINDOWS=0x0490     Windows   98 _WIN32_WINDOWS>=0x0410 *//// 从_WIN32_WINNT值含义可以看出, 如果编译出的PE运行在WinXp以上的Windows可以不用包含<wspiapi.h>int main(int argc, char* argv[]){    SOCKET s = INVALID_SOCKET;    BOOL bVal = FALSE;    /// 其它前置代码没写, 只测试 UDP_NOCHECKSUM 的写法    setsockopt(s, IPPROTO_UDP, UDP_NOCHECKSUM, (const char*)&bVal, sizeof(BOOL));    printf("Hello World!\n");    return 0;}
0 0
原创粉丝点击