4

Possible Duplicate:
Difference between WIN32 and other c string

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

Can anybody tell me , why pointer used for win32 platform and character array for other platform?

Community
  • 1
  • 1
Arif
  • 978
  • 12
  • 29

2 Answers2

2

The code intended to declare an array of length not known at compile time. It was likely written with the assumption that C++ compilers for Windows targets don't support declaring such arrays (for example, Visual C++ doesn't support that). So when compilation is done for Windows targets alloca() function is used to achieve the same effect.

sharptooth
  • 167,383
  • 100
  • 513
  • 979
1

I guess that the compiler used for WIN32 compilation does not support C99 variable length array declarations.

JSON
  • 4,487
  • 22
  • 26