From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: rixed@happyleptic.org Newsgroups: gmane.lisp.guile.user Subject: Re: Now that SCM type is a union... Date: Sat, 13 Aug 2011 12:40:35 +0200 Message-ID: <20110813104034.GA27256@yeeloong.happyleptic.org> References: <20110812124436.GA2223@ccellier.rd.securactive.lan> <74643390-9111-4086-B315-1D2F847A514B@raeburn.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1313232088 28243 80.91.229.12 (13 Aug 2011 10:41:28 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 13 Aug 2011 10:41:28 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Aug 13 12:41:25 2011 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QsBee-0004fn-3b for guile-user@m.gmane.org; Sat, 13 Aug 2011 12:41:24 +0200 Original-Received: from localhost ([::1]:52396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QsBed-0005ve-L9 for guile-user@m.gmane.org; Sat, 13 Aug 2011 06:41:23 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:49778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QsBeb-0005vN-7W for guile-user@gnu.org; Sat, 13 Aug 2011 06:41:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QsBea-0000dp-Ay for guile-user@gnu.org; Sat, 13 Aug 2011 06:41:21 -0400 Original-Received: from smtp5-g21.free.fr ([212.27.42.5]:57963) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QsBeZ-0000d5-Mx for guile-user@gnu.org; Sat, 13 Aug 2011 06:41:20 -0400 Original-Received: from yeeloong (unknown [82.67.194.89]) by smtp5-g21.free.fr (Postfix) with SMTP id 35166D480DD for ; Sat, 13 Aug 2011 12:41:11 +0200 (CEST) Original-Received: by yeeloong (sSMTP sendmail emulation); Sat, 13 Aug 2011 12:40:35 +0200 Mail-Followup-To: rixed@happyleptic.org, guile-user@gnu.org Content-Disposition: inline In-Reply-To: <74643390-9111-4086-B315-1D2F847A514B@raeburn.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 212.27.42.5 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:8708 Archived-At: -[ Sat, Aug 13, 2011 at 01:26:03AM -0400, Ken Raeburn ]---- > ("Is for some reason invalid" is not very descriptive; please include specific compiler messages.) Sorry ; the specific error message was, you guesssed it right: "initializer element is not constant". > That syntax -- the parenthesized type followed by a list of initializers in braces -- is called a "compound literal" (technically not a cast expression) and was added in C99. The value of a compound literal is an anonymous object with a value given by the initializer elements. (It's an lvalue, and can even have its address taken.) That means it's not a "constant expression" and cannot be used for static initialization, under C99 rules. Yes thank you for clarifying this. In this context of initializing a global variable my brain failed to recognize a compound literal. It all make sense now, both why it's used and why gcc is complaining. Now it seams indeed wrong to use an anonymous lvalue as an initializer. > The GCC documentation says that a GCC extension permits such initialization. Even if it was the case, would it be a good idea for header files that are supposed to be included in user programs to rely on a gcc extension ? > From that I'd kind of expect it to work in gnu89 or gnu99 modes, and maybe not c89, but apparently that's not how they did it... It actualy works with gnu89 or c89, but neither gnu99 nor c99 : ---[ foobar.c ]--- struct foo { int a; }; struct foo bar = (struct foo){ 1 }; ---[ /foobar.c ]--- make foobar.o CFLAGS="-std=gnu99" foobar.c:2:26: error: initializer element is not constant same goes for c99 ; while: make foobar.o CFLAGS="-std=c89" works. > Have an initialization function which stuffs SCM_UNSPECIFIED into a bunch of uninitialized SCM variables before making them accessible from other code? Yeah, it's kind of unfortunate. Especially unfortunate if one do not want to rely on gcc specific constructor to initialize it automagically ; and it makes programs that were working with former versions of guile fails to compile which is not so nice. > Maybe we need a separate set of macros for static initialization using SCM_UNDEFINED, SCM_BOOL_F, and friends? I'd like it. Or maybe instead of checking for a PREHISTORIC_COMPILER the header files may check for actual compiler settings (ie. if C99 conformance is required then don't use the union) ; if the underlying encoding of the alternative is the same, of course. > It looks like Guile is compiled in the default (gnu89?) mode, not C99. It has a few places where static variables are initialized using SCM_BOOL_F, which will have the same problem. Yes, whenever c99 becomes the default (it's only 12 years old now).