How to represent int * as an array in totalview?

How can I "immerse" int *, which points to a dynamically allocated array of integers and represent it as a fixed array of int []? Otherwise, if I dive int *, it shows the address and int that it points to, but instead I would like to see an array of all integers.

+3
source share
4 answers

I noticed the TotalView tag on this issue. Are you asking how to see the values ​​in your array in totalview mode? If so, the answer is quite simple.

Suppose you have a pointer p that is of type int *, and now you are pointing to an array with 10 integers.

1. . , - , int he .

,

: p : 0xbfaa1234 : int *

-

0x08059199 β†’ 0x000001a5 (412)

, - . (0x08059199 ) , . , , - "", , .

2. . , . ( , , 0x08059199).

"" . , , . , 0x08059199, .

: * (((int *) p)) : 0x08059199 : int

, -

0x000001a5 (412)

3. . , int [10]. return.

, 0x08059199 10 .

: . , .

"" "" 10 .

[0] - [9], , .

:

  • ( , )

  • " " ,

  • , , . , .

  • "<" .

-,

http://www.roguewave.com/products/totalview/resources/videos.aspx

, " TotalView".

Rogue Wave Software TotalView! dot com com roguewave .

( ) TotalView Product Manager Rogue Wave Software

+8

, , . , ;). , ints, , , test, & test. :

http://www.cplusplus.com/doc/tutorial/pointers/

0

, , ints .

0

int *p, int , , , , :

int *data = malloc(3 * sizeof *data);
int *p;
/* malloc error detection omitted for brevity */
data[0] = 1;
data[1] = 2;
data[3] = 42;

p = data;
assert(p[0] == 1);
assert(p[1] == 2);
assert(p[2] == 42);

, .

, , data, , . , :

void print_array(int *data);

, print_array(data);, . ​​

print_array() :

void print_array(int *data, size_t n);

n , data, . , "" , , , :

data[2] = 0; /* data[0] and data[1] are useful, valid values
                and data[2] is 0 to signify the end of the data */

print_array() :

void print_array(int *data);

data , :

void print_array(int *data)
{
    size_t i;
    for (i=0; data[i] != 0; ++i)
        printf("%d\n", data[i]);
}

So, to answer your question, you can already process the pointer to the actual dynamically distributed data in the form of an array. You must remember the size of the selected data, of course, which you will need to do in a regular array.

-2
source

Source: https://habr.com/ru/post/1729412/


All Articles