0

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.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
rnjai
  • 1,065
  • 2
  • 17
  • 32

2 Answers2

7

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.)

James McNellis
  • 348,265
  • 75
  • 913
  • 977
  • Hi,i just made a minor edit to the question and added two more functions which are platform dependent. – rnjai Dec 20 '13 at 06:18
  • 1
    `wcstombs_s` falls under the second bullet of my answer: it was nonstandard but was standardized in C11 Annex K. I don't know whether there are behavioral differences in that particular function (I haven't finished a full analysis of our conformance for these functions yet). `WideCharToMultiByte` is not a C Runtime function, it's a Windows API, and is 100% platform-dependent. Are you going to ask this same question about every function you encounter? – James McNellis Dec 20 '13 at 06:33
  • Thank you for the answer,Sorry for the trouble. – rnjai Dec 20 '13 at 06:44
  • It's no trouble, but I wonder what your broader goal is. Are you trying to stick to standard, portable APIs in your code (and, if so, portable across what set of systems)? With more information about what you are trying to do, I or someone else might be able to provide better references to help you to identify platform-specific functionality. – James McNellis Dec 20 '13 at 06:57
  • Yes we do need support across Mac,Solaris,Linux besides windows.So yes something portable across all these will save some trouble. – rnjai Dec 20 '13 at 08:32
2

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.

Joker_vD
  • 3,715
  • 1
  • 28
  • 42