WIN32和其他C字符串之间的区别 [英] Difference between WIN32 and other c string
问题描述
我有一个小程序,这里面code读取文件:
I got this code inside a small program to read a file:
#ifdef WIN32
unsigned char *buffer = (unsigned char *)alloca((unsigned int)ui.length);
#else
unsigned char buffer[ui.length];
#endif
为什么要使用指针为Win32平台和字符数组其他平台?
Why is a pointer used for Win32 platform and character array for other platforms?
推荐答案
这似乎previously到C99定义堆栈上的变长数组没有得到支持。本质上的alloca做到这一点。看来这个程序员有一个WIN32编译器不支持VLA的这样使用(的良好支持,但非标)的alloca。
It seems previously to C99 defining a variable length array on the stack was not supported. alloca essentially does this. Seems this programmer had a WIN32 compiler that didn't support VLA's so was using (the well-supported but non-standard) alloca.
更多关于这堆栈溢出:为什么不的alloca认为好的做法呢? 这相当有用阵列摘要 HTTP://www.programmersheaven .COM / 2 /指针和阵列页-2阿瑟堆栈溢出帖子中提到。
More on this in stack overflow: Why is alloca not considered good practice? and this rather useful array summary http://www.programmersheaven.com/2/Pointers-and-Arrays-page-2 mentioned by Arthur on the stack overflow post.
这篇关于WIN32和其他C字符串之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!