之间我有一个小程序,这里面的代码读取文件:差异WIN32和其他C字符串
#ifdef WIN32
unsigned char *buffer = (unsigned char *)alloca((unsigned int)ui.length);
#else
unsigned char buffer[ui.length];
#endif
为什么用于Win32平台和字符数组用于其他平台的指针?
之间我有一个小程序,这里面的代码读取文件:差异WIN32和其他C字符串
#ifdef WIN32
unsigned char *buffer = (unsigned char *)alloca((unsigned int)ui.length);
#else
unsigned char buffer[ui.length];
#endif
为什么用于Win32平台和字符数组用于其他平台的指针?
它似乎以前C99不支持在栈上定义一个可变长度数组。 alloca基本上这样做。看起来这个程序员有一个不支持VLA的WIN32编译器,所以使用了(支持良好但非标准的)alloca。
更多关于这个在堆栈溢出:Why is the use of alloca() not considered good practice?和这个相当有用的数组摘要http://www.programmersheaven.com/2/Pointers-and-Arrays-page-2由Arthur在堆栈溢出帖子中提到。
Windows没有什么特别之处。不同之处在于Microsoft Visual C++ does not supportVariable-length array (VLA)(C99功能),作者可能认为MSVC == WIN32,因此创建了该条件。