View previous topic :: View next topic |
Author |
Message |
ch_dupre
Joined: 22 Aug 2006 Posts: 18
|
sizeof(structure->array) |
Posted: Tue Oct 17, 2006 9:26 am |
|
|
Hello there,
I am trying to optain the size of an array which is a member of a pointer to a structure.
Here is my sample code:
*****************************************
typedef struct
{
int i;
char array[20];
} structure;
void main()
{
structure example;
structure* pexample;
pexample = &example;
fprintf(COM1, "%d and %d\n", sizeof(example.array), sizeof(pexample->array));
}
*********************************************
I get "20 and 2" as output. I was expecting "20 and 20".
In my application, I only have a pointer to the structure. Is it possible to obtain the size of the array?
Thanks
Christophe D. |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
Re: sizeof(structure->array) |
Posted: Tue Oct 17, 2006 12:40 pm |
|
|
ch_dupre wrote: | I get "20 and 2" as output. I was expecting "20 and 20". |
Yeah, I would expect "20 and 20" too. All I can add is that the pointers in v3.x are a dark matter, and pinters in v4.x are in the works. |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Tue Oct 17, 2006 8:51 pm |
|
|
I think that sizeof is evaluated at compile time, this is why it shows your pointer as long (2 bytes). |
|
|
|