Click to See Complete Forum and Search --> : A question about #define WIN32 and "sbrk"


George Ma
September 1st, 2002, 06:07 AM
Hi, everyone!

Look at the source codes,

--------
/* #define WIN32 */
#ifdef WIN32
#define MORECORE wsbrk
#endif
--------

Such is the comments,

--------
WIN32 (default: undefined)
Define this on MS win (95, nt) platforms to compile in sbrk emulation.
--------

I have two questions,

1. What means WIN32? When the variable "WIN32" becomes
defined? When it is not defined?

2. What means "sbrk" in the comment? What means "wsbrk"?

Btw: the software is written for both Windows and Linux
platforms.

Cheers,
George

willchop
September 1st, 2002, 01:31 PM
George,

WIN32 is a preprocessor definition that when defined includes
code specific to the Windows platform. My compiler (VC6)
defines WIN32 in the project settings/C++/preprocessor
dialog. Other compilers will define their target platform in
other places.

In your case when your code is compiled with a Windows
compiler the preprocessor will define MORECORE as wsbrk.
Although I'm not sure what sbrk does, the "w" prefix version
being used on the Windows platform might mean a wide-
char version of sbrk.

-Regrads, willchop

willchop
September 1st, 2002, 01:43 PM
FYI: ReorX posted the meaning of sbrk in this cross-posted thread. See "Visual C++ Programming" forum.

Regards, willchop

cup
September 1st, 2002, 03:20 PM
sbrk on Unix is the routine that allocates memory. This is a very low level routine and you shouldn't need to call it as it is called from new and malloc.

As willchop said, it would help if you only posted your questions in one forum. That way several people won't be wasting their time answering questions that have already been answered.