From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16977 invoked by alias); 18 Aug 2004 00:21:50 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 16970 invoked from network); 18 Aug 2004 00:21:49 -0000 Received: from unknown (HELO mproxy.gmail.com) (64.233.170.198) by sourceware.org with SMTP; 18 Aug 2004 00:21:49 -0000 Received: by mproxy.gmail.com with SMTP id 77so128729rnl for ; Tue, 17 Aug 2004 17:21:49 -0700 (PDT) Received: by 10.38.70.6 with SMTP id s6mr389426rna; Tue, 17 Aug 2004 17:21:48 -0700 (PDT) Message-ID: <9ebd65110408171721146dd77@mail.gmail.com> Date: Wed, 18 Aug 2004 00:22:00 -0000 From: Adam Monsen Reply-To: Adam Monsen To: Gabor Greif Subject: Re: warn/croak on "string" "string" auto-joins Cc: gcc@gcc.gnu.org In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: X-SW-Source: 2004-08/txt/msg00834.txt.bz2 Hi Gabor, Thanks for your input! On Wed, 18 Aug 2004 01:25:10 +0200, Gabor Greif wrote: > Adam Monsen wrote: > > String auto-joins can be dangerous. Is there a way to tell the > > compiler to warn/croak when an auto-join occurs? > > > > For instance, find the bug in this code: > > > > char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", > > "Aug" "Sep", "Oct", "Nov", "Dec"}; > > > > If not, I'd like to suggest a way to ask the compiler to strictly > > check for this. > > The compiler cannot shield you from all programmer errors. Agreed. > This would have helped early and is good practice: > > char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", > "Aug" "Sep", "Oct", "Nov", "Dec"}; > > --> high probability warning I'm not sure I understand, what does "high probability warning" mean? I get no errors/warnings from the following: #include int main( void ) { char *months[15] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug" "Sep", "Oct", "Nov", "Dec"}; printf("7: %s\n", months[8]); return 0; } compiled with 'gcc -Wall -pedantic -ansi', using GCC 3.3.3. > Cheers, > > Gabor > > PS: I often assemble longer (format) strings from smaller ones > by means of macros, so if this ever to become a warning I'd > prefer to exclude macro-expanded occurrences. But you currently have no use for the warning, correct? Or, do you feel it is useful? I'm confused. -- Adam Monsen http://adammonsen.com/