lkml.org 
[lkml]   [2006]   [Oct]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] [kernel/ subdirectory] constifications
>> > > - 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'
--
\
 
 \ /
  Last update: 2006-10-09 22:13    [W:0.042 / U:0.532 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site