Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761303AbXHBUMm (ORCPT ); Thu, 2 Aug 2007 16:12:42 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1759782AbXHBUMP (ORCPT ); Thu, 2 Aug 2007 16:12:15 -0400 Received: from cantor2.suse.de ([195.135.220.15]:39471 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759619AbXHBUMO (ORCPT ); Thu, 2 Aug 2007 16:12:14 -0400 To: Guennadi Liakhovetski Cc: linux-kernel@vger.kernel.org Subject: Re: gcc fixed size char array initialization bug - known? References: From: Andi Kleen Date: 02 Aug 2007 23:06:44 +0200 In-Reply-To: Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1043 Lines: 33 Guennadi Liakhovetski writes: > Hi > > I've run across the following gcc "feature": > > char c[4] = "01234"; > > gcc emits a nice warning > > warning: initializer-string for array of chars is too long > > But do a > > char c[4] = "0123"; > and - a wonder - no warning. It's required by the C standard. 6.7.8.14 of C99: `` An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array. '' Note the "if there is room". I believe the rationale is that it still allows to conveniently initialize non zero terminated strings. -Andi - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/