Re: Controlling Static Data and Memory Organization...If Possible...



Gordon Burditt wrote:
brplummer@xxxxxxxxx wrote:

#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);
}
.... snip ...

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.
.



Relevant Pages

  • Re: Init.c, making it chroot
    ... that's located at a special place inside the chroot. ... int devfs; ... typedef struct init_session { ... main(int argc, char *argv) ...
    (freebsd-hackers)
  • [PATCH]a tar filesystem for 2.6.10-rc1-mm3
    ... +static int tarfs_readdir(struct file * filp, ... struct tarent *dir_tarent, *ent; ... +static int tarfs_readlink(struct dentry *dentry, char *buffer, int buflen) ...
    (Linux-Kernel)
  • [PATCH] a tar filesystem for 2.6.*(easily access tar file)
    ... +static int tarfs_readdir(struct file * filp, ... struct tarent *dir_tarent, *ent; ... +static int tarfs_readlink(struct dentry *dentry, char *buffer, int buflen) ...
    (Linux-Kernel)
  • Re: Memory Structure Pointer Problems
    ... typedef struct sta { ... char* name; ... int num_cmpnds; ... A pointer to a struct cmp is almost ...
    (comp.lang.c)
  • Re: Connector - how to start?
    ... It seems like one of the Red Hat guys had some netlink documentation ... Netlink is fast but not faster than char device for example, ... static int need_exit; ... struct nlmsghdr *nlh; ...
    (Linux-Kernel)