开发者

Difference between WIN32 and other c string

I got this code ins开发者_开发知识库ide 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

Why is a pointer used for Win32 platform and character array for other platforms?


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.

More on this in stack overflow: Why is the use of 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.


There is nothing special in Windows. The difference is Microsoft Visual C++ does not support Variable-length array (VLA) (a C99 feature), and the author probably thinks MSVC == WIN32, thus that condition was created.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜