Re: Controlling Static Data and Memory Organization...If Possible...
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Tue, 25 Nov 2008 20:46:57 -0500
Gordon Burditt wrote:
brplummer@xxxxxxxxx wrote:.... snip ...
#include <stdio.h>
struct Stuff {
const char * name;
int value;
} StuffArray[] = {
{"Bill",1},
{"Sally",2},
{"Victor",3}
};
int main(void) {
printf("Bill is at :0x%08d\n",(void *)StuffArray[ 0 ].name);
printf("Sally is at :0x%08d\n",(void *)StuffArray[ 1 ].name);
printf("Victor is at:0x%08d\n",(void *)StuffArray[ 2 ].name);
}
Then put them in an object in such a way that the memory layout is
guaranteed. Say, an array. One way to do this (as you suggest
below) is to change struct Stuff so name is a char array, not a
pointer. You will have to make the char array big enough for the
largest name to fit, and it will be that big for every struct in
the array.
In addition he is invoking undefined behaviour, by attempting to
print a pointer with a %d descriptor. %p will print void*
pointers.
He can also use a linked list, which will remove the need to
configure a maximum configuration.
I have reinjected the attribution which you carelessly snipped.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
.
- References:
- Controlling Static Data and Memory Organization...If Possible...
- From: brplummer
- Re: Controlling Static Data and Memory Organization...If Possible...
- From: Gordon Burditt
- Controlling Static Data and Memory Organization...If Possible...
- Prev by Date: Re: while ((a != 0) and (q<k))
- Next by Date: Re: *scanf in Harbison and Steele
- Previous by thread: Re: Controlling Static Data and Memory Organization...If Possible...
- Next by thread: Re: Controlling Static Data and Memory Organization...If Possible...
- Index(es):
Relevant Pages
|