By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,186 Members | 1,530 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,186 IT Pros & Developers. It's quick & easy.

VC7.1 bug: managed call to wcschr

P: n/a
/// 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
Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.
--------------------

Nov 17 '05 #2

P: n/a
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
""Gary Chang"" <v-******@online.microsoft.com> wrote in message
news:el**************@cpmsftngxa06.phx.gbl...
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. --------------------

Nov 17 '05 #3

P: n/a
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.
--------------------

Nov 17 '05 #4

P: n/a
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.
--------------------

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.