VC7.1 bug: managed call to wcschr

G

Guest

/// Compile with "cl /Zc:wchar_t /clr bug.cpp"

#include <stdio.h>
#include <string.h>

#define TEST const wchar_t* p = wcschr( L"aa:aa", L':' ); printf(
"%ls\n", p );

#pragma managed
void f_managed()
{
TEST
}

#pragma unmanaged
void f_unmanaged()
{
TEST
}

#pragma managed
void main()
{
f_managed();
f_unmanaged();
}

Results:

(null)
:aa
 
G

Gary Chang

Hi,

It seems not a bug of managed call to wcschr function, my opinion is that
the wcschr will return a wchar_t pointer, for C++ run-time function, the
wchar_t is defined as unsigned short which the wcschr would accept, but in
managed C++, if you compile with the /Zc:wchar_t compliance switch, the
compiler enable wchar_t as an intrinsic type System::Char, so the wcschr
call's return value is not incompatible with the System::Char* p...

I tested the program will work as expected as compile with "cl /clr
bug.cpp"
:aa
:aa


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
G

Guest

Thank you for your response, but you are not right.

wcschr() takes "const wchar_t*" and returns "wchar_t*". So as long as I
assign the result to "wchar_t*" or "const wchar_t*", all should work. Yes,
the bug appears only when I enable the native wchar_t type, which is not
System::Char (managed), by the way, but just a native C++ type.

The problem happens in 7.1 and fixed in 8.0, so I don't think Microsoft will
fix the bug in 7.1.

Cheers
 
G

Gary Chang

Hi,

I have consulted this problem with the VC dev team members, when you enable
the /Zc:wchar_t compliance switch, the wchar_t would be defined as managed
"chars(System::Char) in managed compile unit.

They confirmed this problem is caused by the wchar_t type is not always
marshaled correctly across managed/unmanaged transition boundaries in VC
7.1 2003.

It is a known issue in VS.NET 2003, and was fixed in Whidbey.


Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
G

Gary Chang

Hi,

Do you have any more concerns on this issue, if so please feel free to post
here.


Good Luck!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top