[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Pine.LNX.4.61.0610092206400.23379@yvahk01.tjqt.qr>
Date: Mon, 9 Oct 2006 22:08:30 +0200 (MEST)
From: Jan Engelhardt <jengelh@...ux01.gwdg.de>
To: Arjan van de Ven <arjan@...radead.org>
cc: Helge Deller <deller@....de>, Linus Torvalds <torvalds@...l.org>,
Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [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'
--
Powered by blists - more mailing lists