On Fri, 20 Apr 2007 18:40:26 -0400 Sam C. Nicholson !! wrote: > Glenn Fowler wrote: > > I've been at this so long you think I should know better > > > > I've been under the apparently mistaken assumption that > > if I dilligently pepper struct definitions and subsequent > > declarations and initializations with "const" that the compiler > > will attempt to place that data in readonly text > > > > I've done this with the libast tables in conftab.c lc.c > > but nm and size show the data going to the .data section
I did some more tests and the difference finally popped out struct Foo_s { const char* bar; }; const struct Foo_s foo; with PIC enabled (I had been examining shared lib/dll code) the struct is relegated to .data because foo.bar needs runtime relocation with noPIC most compilers by default will put foo in .rodata or its equivalent I knew this and forgot it (probably 10x already) one alternative is to const char bar[SOME_MAX_SIZE]; or to set up a screwy string table accessed by const indices, possibly generated by an offline preprocessor for now the code will stand as is until it becomes a performance issue -- Glenn Fowler -- AT&T Research, Florham Park NJ --