The difference between WIN32 and another line c

I got this code inside a small program to read the file:

#ifdef WIN32 unsigned char *buffer = (unsigned char *)alloca((unsigned int)ui.length); #else unsigned char buffer[ui.length]; #endif 

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

+1
source share
2 answers

It seems that earlier C99, which defines an array of variable lengths on the stack, was not supported. alloca basically does. This programmer seems to have had a WIN32 compiler that did not support VLA, so it used (well-supported, but non-standard) alloca.

See the stack overflow for more on this: Why isn't using alloca () considered good practice? and this is a pretty useful summary of the http://www.programmersheaven.com/2/Pointers-and-Arrays-page-2 array mentioned by Arthur in the column.

+2
source

There is nothing special about Windows. The difference in Microsoft Visual C ++ does not support Variable Length Array (VLA) (C99 function), and the author probably considers MSVC == WIN32, so this condition was created.

+2
source

Source: https://habr.com/ru/post/1345833/


All Articles