ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I agree with ken and jim that the addresses assigned will be architecture specific. and the addresses shown on ur machine are easily justified as well. but the values which I see on my machine are not.
U can see below that the difference between address of cool3 and cool2 is 0x10 bytes(16 bytes) where as size of cool3 is 20 bytes?
and why is there a gap of 40 bytes in cool and cool3 address? i mean even if we consider memory alignment, padding etc, i couldnt find out the reason for so much gap. i mean this gap wont be used by anything at all. so is it that that memory is being wasted?
printf("\nSizeof cool is %d \n", sizeof(cool));
printf("\nSizeof cool3 is %d \n", sizeof(cool3));
printf("\nSizeof cool2 is %d \n", sizeof(cool2));
printf("\nSizeof cool4 is %d \n", sizeof(cool4));
printf("address of cool is %x\n", &cool);
printf("address of cool3 is %x\n", &cool3);
printf("address of cool2 is %x\n", &cool2);
printf("address of cool4 is %x\n", &cool4);
printf("\n&heh1 is %x ", &heh1);
printf("\n&heh2 is %x ", &heh2);
}
int main()
{
hello();
return 0;
}
Output:
=======
Sizeof cool is 8
Sizeof cool3 is 20
Sizeof cool2 is 0
Sizeof cool4 is 2
address of cool is bfffbd28
address of cool3 is bfffbd00
address of cool2 is bfffbcf0
address of cool4 is bfffbcee
I agree with ken and jim that the addresses assigned will be architecture specific. and the addresses shown on ur machine are easily justified as well. but the values which I see on my machine are not.
U can see below that the difference between address of cool3 and cool2 is 0x10 bytes(16 bytes) where as size of cool3 is 20 bytes?
and why is there a gap of 40 bytes in cool and cool3 address? i mean even if we consider memory alignment, padding etc, i couldnt find out the reason for so much gap. i mean this gap wont be used by anything at all. so is it that that memory is being wasted?
On what kind of system are you running your test program?
If "uname" is available, what does "uname -a" tell you ?
What options are you giving the C compiler to compile and build?
address of cool is 0xbfac2008
address of cool3 is 0xbfac1fe0
address of cool2 is 0xbfac1fd0
address of cool4 is 0xbfac1fce
&heh1 is 0xbfac1fc8
&heh2 is 0xbfac1fb0
That's definitely a dumb question. Your time would be *much* better spent reading a book on compilers, than counting byte offsets in random variable declarations.
If you insist, however: please:
a) follow varun_shrivastava's advise, and try to interpret the assembler output
b) analyze the organization of the entire (elf?) format executable
c) speculate on why data in the file is organized the way it it
PS:
I think that's the first time I've ever seen variables named after "Beavis and Butthead" expressions. Oh well...
paulsm4
I hav obviously read books on compilers and thats why I asked this question. Still Cudnt find the answer so thought posting it on this forum may help but forgot that some ppl prefer reading books than trying something. Thanks for your suggetsions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.