:: Re: [DNG] Making sense of C pointer…
Página superior
Eliminar este mensaje
Responder a este mensaje
Autor: Emiliano Marini
Fecha:  
A: Edward Bartolo
Cc: dng
Asunto: Re: [DNG] Making sense of C pointer syntax.
This is correct:

int **L ===> Address1(preallocated) -----> Address2(not allocated) ----->
> int (not allocated)
>


When you declare a variable, the compiler will reserve memory space to
store it.

No matter how may asterisks a variable has, from the compiler's view it's
only a memory address. So it will reserve space to store an address:

int *****x;

x will store a memory address, so the compiler has to reserve 8 bytes
(amd64) for it.

Conclusion: the size of a pointer will be always the same, no matter what
is pointing to (an integer, a char, an address...)


On Tue, Mar 29, 2016 at 9:00 AM, Edward Bartolo <edbarx@???> wrote:

> Hi,
>
> As far as I know, the compiler automatically allocates memory for the
> address where a pointer is saved. The unallocated part is the data
> attached to a pointer. What happens with a pointer to a pointer like
> void**? Does the compiler allocate memory for two addresses with the
> first one in the chain pointing to the second one? Does it allocate
> memory only for the first address?
>
> What I can say about pointers:
>
> a) int * K ===>    Address(preallocated) -------------------> integer
> [ not preallocated ]

>
> b) void** V ===> Address1 (preallocated) ------> Address2(preallocated)
>
> OR:
>
> void** V ===> Address1 (preallocated) -----> Address2(not preallocated)
>
> ?
>
> c) int **L ===> Address1 (preallocated) -----> Address2(allocated)
> -----> int (not allocated)
>
> OR
>
> int **L ===> Address1(preallocated) -----> Address2(not allocated)
> -----> int (not allocated)
>
> By 'preallocated' I mean the compiler will automatically generate code
> to allocate memory for the actual pointer not the data.
>
> d) Is this allowed: void***, int***, double***, etc?
> _______________________________________________
> Dng mailing list
> Dng@???
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
>