3

Microsoft documentation shows both _tcsnicmp and _tcsncicmp (note the extra c) as TCHAR.H equivalents of _strnicmp for doing string comparisions. I'm not sure which one I should be using.

What is the difference between the two methods?

My best guess is that the nc version takes a count in number of characters and the n version takes a count in number of bytes.

Mashmagar
  • 2,556
  • 2
  • 29
  • 38

2 Answers2

5

All of the _tcs functions are actually macros, and will resolve down to an equivalent function depending on which of _UNICODE or _MBCS macros are defined for the build.

Looking at the documentation, the two functions are identical except for the case when _MBCS is defined, in which case they resolve to _mcsnicmp or _mbsnbicmp. The difference between those, as you stated, is whether the count is in characters or bytes.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
-1

To me it seems you should be using neither.

Identifiers starting with a underscore should only be used by compilers/implementations and not in normal code.

Perhaps you could elaborate more about what you are trying to do?

orlp
  • 112,504
  • 36
  • 218
  • 315
  • 2
    Don't agree that `identifiers starting with an underscore should only be used by compilers/implementations`, there are lot of functions taken from prosix with same names but starting with underscore in visual c++ (say `_read()`, `_write()`, `_access()`, `_pipe()` ...) – Mihran Hovsepyan May 05 '11 at 15:33
  • I'm trying to do case-insensitive Unicode-compliant string comparison. The case-insensitive version of `strcmp` is `_stricmp`. I have no idea why they added an underscore, but I don't think it has to do with compiler/non-compiler usage. – Mashmagar May 05 '11 at 15:34
  • @Mihran Hovespyan: Then Microsoft is violating standards, but meh, that ain't the first time. Then disregard my answer (reading on MS's forums I see people recommending this function). – orlp May 05 '11 at 15:35
  • @nightcracker why `Microsoft is violating standards`? Do you mean ISO standart of C++? – Mihran Hovsepyan May 05 '11 at 15:38
  • @Mihran Hovespyan: http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier – orlp May 05 '11 at 15:41
  • @nightcracker here says `Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace`, but Microsoft as implementor of his compiler and library can use them, so no rule is violatied. – Mihran Hovsepyan May 05 '11 at 15:47
  • Yes, but the user shouldn't use them, they should be reserved and used by the implementation only, unless unavoidable. – orlp May 05 '11 at 15:49
  • 4
    @nightcracker you're misunderstanding the restriction. "Reserved" doesn't mean you can't use such a symbol, only that you can't define one. The difference is subtle but important. Microsoft has taken on this convention to make sure that their library extensions don't conflict with user defined symbols or later revisions to the standards. – Mark Ransom May 05 '11 at 16:00