473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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 1365
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: bq | last post by:
Hello, Two questions related to floating point support: What C compilers for the wintel (MS Windows + x86) platform are C99 compliant as far as <math.h> and <tgmath.h> are concerned? What...
3
by: Pablo Gutierrez | last post by:
I have a C# method that reads Binary data (BLOB type) from a database and returns the data an array of bytes (i.e byte outbyte = new byte;). The BLOB column is saved into the database by a C...
5
by: _BNC | last post by:
I've converted " byte" to "byte *" at times, using 'unsafe' and fixed { .... }, but the reverse does not seem to work. In this case, a C++ DLL returns a byte * and a length. What is the best...
3
by: Mochuelo | last post by:
Hi, In the constructor of a class, I am taking as a parameter the reference to a "bool", as in this code: ----------------------- public class TCP_synch_client { public string address...
4
by: Frederick Gotham | last post by:
Does "bool" behave _exactly_ like any other integer type, except for when it comes to integer promotion? Consider the following C function whose purpose it is to calculate the quantity of equal...
2
by: abelniel | last post by:
Hi all, When I use "bool" type in my program, gcc pop an error error: `bool' undeclared (first use in this function) I have included the following lib: #include <stdio.h> #include...
6
yabansu
by: yabansu | last post by:
Hi all, I think most of you probably know the two .NET framework functions, namely Encoding.GetBytes(string) and Encoding.GetString(byte), to convert string into byte array and vice versa. Now,...
3
by: knguyen | last post by:
Hello, I was trying to compile the source code from "Design Patterns: Elements of Reusable Object-Oriented Software", which can be obtained from here...
2
by: Marcel Kloubert | last post by:
Hi! Example: public bool? IsChecked { get { throw new NotImplementedException(); } } What does the question mark after the bool mean ("bool?")?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.