CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

sizeof(structure->array)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ch_dupre



Joined: 22 Aug 2006
Posts: 18

View user's profile Send private message

sizeof(structure->array)
PostPosted: Tue Oct 17, 2006 9:26 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: sizeof(structure->array)
PostPosted: Tue Oct 17, 2006 12:40 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 17, 2006 8:51 pm     Reply with quote

I think that sizeof is evaluated at compile time, this is why it shows your pointer as long (2 bytes).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group