468,733 Members | 1,618 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,733 developers. It's quick & easy.

Subject: "bool[] {byte[]}" reported as type in the locals window

In C#, I am calling a method implemented in Managed C++ that returns an array
of booleans. This method in turn calls unto unmanaged C++ code that returns
an unsigned byte array, which is implicitly casted to a bool __gc [].
However, in my client C# app, when I examine this array in the locals window,
it shows "bool[]" as the type of the array and "byte" as the type of each
element. If I try this in Whidbey beta, it shows "bool[] {byte[]}" and "bool
{byte}" as the types.

If I create an array of booleans in my C# program, I only see "bool" in the
name--no "bytes". Am I doing something wrong in treating a boolean array as
a byte array?

Thanks,
-- Chris
Nov 17 '05 #1
2 1183
Chris Wood wrote:
If I create an array of booleans in my C# program, I only see "bool" in
the name--no "bytes". Am I doing something wrong in treating a boolean
array as a byte array?


The statement "implicitly casted to a bool __gc []" is very suspicious.
Would you mind sharing an example that does this?

Because a "bool __nogc []" and "bool __gc []" are very different data
structures in C++, the only way to safely convert between them is to write
code that does so (i.e. write a for loop).

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.

Nov 17 '05 #2
Chris Wood wrote:
Everything appears to work fine when I do this, it's just that the
debugger displays the data type as "byte" for each element, rather than
"bool".


That's because the type is actually bool. The difference is between dynamic
type and static type. The dynamic type of an object never changes. Every
object is tagged so that the CLR (and thus the debugger) can tell what the
real type is.

This program demonstrates that idea:

#using <mscorlib.dll>
using namespace System;

bool ReadBools() __gc []
{
unsigned char buffer __gc [] = new unsigned char __gc [3];
return buffer;
}

int main() {
Object* o = ReadBools();
Console::WriteLine(o);
}

It's also worth noting that while the compiler is allowing the conversion,
it really shouldn't be doing that. The code is unverifiable.

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Pablo Gutierrez | last post: by
3 posts views Thread by Mochuelo | last post: by
4 posts views Thread by Frederick Gotham | last post: by
2 posts views Thread by abelniel | last post: by
3 posts views Thread by knguyen | last post: by
2 posts views Thread by Marcel Kloubert | last post: by
reply views Thread by zhoujie | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.