سؤال

I am a little confused with respect to the difference in the functions which are defined with/without the wcs/_w/_mbs prefix.
For Example:

  • fopen(),_wfopen()
    On msdn it is given that:

The fopen function opens the file that is specified by filename. _wfopen is a wide-character version of fopen; the arguments to _wfopen are wide-character strings. Otherwise, _wfopen and fopen behave identically.

I just had a doubt whether there is any platform dependence to windows associated with the addition of the "_w" prefix.

  • strcpy(),wcscpy(),_mbscpy()
    On msdn it is given that:

wcscpy and _mbscpy are, respectively, wide-character and multibyte-character versions of strcpy.

Again there is a doubt if the addition of "wcs" or "_mbs" is platform dependent.

EDIT:

  • Is WideCharToMultiByte function also platform dependent?

WideCharToMultiByte is not a C Runtime function, it's a Windows API,hence it is platform dependent

  • Similarly is wcstombs_s function also platform dependent?

It was nonstandard but was standardized in C11 Annex K.

هل كانت مفيدة؟

المحلول

The wcs* functions like wcscpy are part of the C Standard Library. The _wfopen function and other _w* functions are extensions, as are the multibyte string functions like _mbscpy.

For the most part, Visual C++ C Runtime (CRT) functions that have a leading underscore are extensions; functions that do not have a leading underscore are part of the C Standard Library.

There are two main exceptions, where extensions may not have leading underscores:

  • There are several extension functions, declared with an underscore prefix, that have prefixless aliases for backwards source compatibility. These aliases are deprecated, and if you try to use them you'll get a suppressable deprecation warning (C4996).

  • There are _s-suffixed secure alternative functions to some C Standard Library functions, e.g. scanf_s. These are declared by default, but their declarations may be suppressed by defining the macro __STDC_WANT_SECURE_LIB__ to have the value 0.

    (These functions were actually added to C11 in the optional Annex K, but note that there are a few differences between what is specified in the C Standard and what is implemented by Visual C++. The differences are due to a historical accident.)

نصائح أخرى

wcscpy is standard. _mbcscpy is specific to MS VC.

That's why there is an underscore at the start: names with leading underscore are reserved for implementation-specific things.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top