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

G

Guest

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
 
B

Brandon Bray [MSFT]

Chris said:
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).
 
B

Brandon Bray [MSFT]

Chris said:
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.
 

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