Dynamic bool array has only one value?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
YoMomIsANiceLady
Posts: 33
Joined: February 2nd, 2017, 8:20 am

Dynamic bool array has only one value?

Post by YoMomIsANiceLady » February 13th, 2017, 4:39 am

What is going on here. Can somebody explain?

I have

Code: Select all

 bool *map; 
in the header file and then I want to initalize it based on the input. There should be 35 bools in the map array (5*7) but there's only one.

http://i.imgur.com/kBfvrpd.png

...and yes, I am coding at half past 4 in the morning
"Life is like death, but completely different"
- Ivan Gašparovič

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Dynamic bool array has only one value?

Post by chili » February 13th, 2017, 4:58 am

Yeah, a dynamically allocated array is managed by a pointer, but the debugger has no way of knowing whether that pointer points to a block of memory or to a single value.

Try adding a custom watch and casting (bool(*)[size_of_dyn_arr])map
Chili

User avatar
YoMomIsANiceLady
Posts: 33
Joined: February 2nd, 2017, 8:20 am

Re: Dynamic bool array has only one value?

Post by YoMomIsANiceLady » February 13th, 2017, 7:42 am

^ I don't know what you mean by that casting.

But I tried adding a custom watch for the individual points and that worked. So yay!
"Life is like death, but completely different"
- Ivan Gašparovič

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Dynamic bool array has only one value?

Post by LuisR14 » February 13th, 2017, 10:01 am

it's a cast to a bool array that has a size of size_of_dyn_arr
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

User avatar
YoMomIsANiceLady
Posts: 33
Joined: February 2nd, 2017, 8:20 am

Re: Dynamic bool array has only one value?

Post by YoMomIsANiceLady » February 13th, 2017, 12:59 pm

Oh I figured it out. The simplest method to show the full array is type

nameOfArray, arraySize

into watch list.
So in my case I would type in:

map, 35

and it shows the whole thing
"Life is like death, but completely different"
- Ivan Gašparovič

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Dynamic bool array has only one value?

Post by chili » February 13th, 2017, 1:06 pm

The one I showed you makes it show the whole array too, but I wasn't aware of this usage. Good to know, thanks for sharing.
Chili

Post Reply