Sunday 12 February 2017

MBCS and other Compiler Flags in Visual C/C++

When writing C and C++ code in Visual Studio understanding your compiler flags is critical.

These are configured under -

Project -> Properties -> Configuration Properties -> C/C++ -> Preprocessor.

One of the default ones you might come across is _MBCS, which stands for multi-byte character set (an alternative to _UNICODE).  These directives define what the compiler understands a "character" to be. ASCII and ANSI are not multi-byte character encodings.

A useful directive if you want to use the "traditional" C functions like fopen etc.which are deprecated in recent Visual Studio releases is _CRT_SECURE_NO_WARNINGS. (CRT is shorthand for C runtime).

More detail on why functions like fopen are deprecated can be found in this article on Security Features in the CRT.

No comments: