>> > > - completely constify string arrays, thus move them to the rodata section
>> >
>> > note that gcc 4.1 and later will do this automatically for static things
>> > at least...
>>
>> Are you sure ?
>>
>> At least with gcc-4.1.0 from SUSE 10.1 the strings array _pointers_ are not moved into the rodata section without the second "const":
>> const static char * const x[] = { "value1", "value2" };
>
>hmm I could have sworn GCC does this automatic nowadays as long as it
>can prove you're not writing to the thing (eg static and not passing the
>pointer to some external function).....
Arjan seems right:
22:07 ichi:/dev/shm > cat test.c
#include <stdio.h>
static const char *x[] = {"0", "1", NULL};
int main(void) {
int i;
for(i = 0; i < 3; ++i)
printf("%s\n", x[i]);
return 0;
}
22:07 ichi:/dev/shm > cc test.c -c && nm test.o | grep x
00000000 d x
22:07 ichi:/dev/shm > cc test.c -c -O2 && nm test.o | grep x
00000000 r x
>(even if gcc does this perfect I'm still in favor of the explicit const,
>just to catch stupid code with a warning)
Me² (read: ack)
-`J'
--
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]