#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif
this is the header for the default win32 c app on codeblocks
CodePudding user response:
It ensures that both UNICODE
and _UNICODE
are defined if one of them is.
CodePudding user response:
What do you think it does?
It ensures that if either of the UNICODE or _UNICODE preprocessor symbols are defined, then both UNICODE and _UNICODE are defined.
Which in itself does nothing.
We can assume that there are places in the header files that include different versions of the code depending upon whether UNICODE is defined. Most likely to define functions that use Unicode strings or ASCII.
So if a programmer wanted to use Unicode strings, he'd define UNICODE and link the Unicode versions of the standard libraries, if not he'd leave UNICODE undefined and link the ASCII versions.
But why UNICODE and _UNICODE? We can assume that sometime after the compiler vendor shipped a version using UNICODE someone decided that having vendors setting precompiler symbols in the global namespace was a bad idea.
So the vendor changed to use _UNICODE instead. But because they have some unknown number of customers who already have code using UNICODE, and they don't want to break existing code, they do this little trick - defining both if either is defined.
The expectation was that at some point they'll stop supporting UNICODE, and support only _UNICODE.
But my guess is that will never happen.
CodePudding user response:
extended of molbdnilo,
in a nutshell,
UNICODE is used by Windows headers
,
whereas
_UNICODE is used by C-runtime/MFC headers
.
C-runtime is:
The C runtime Library (CRT) is the part of the C Standard Library that incorporates the ISO C standard library.for more knowledge
MFC headers:
The Microsoft Foundation Class (MFC) Library provides an object-oriented wrapper over much of the Win32 and COM APIs. Although it can be used to create very simple desktop applications, it is most useful when you need to develop more complex user interfaces with multiple controls