From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ken Raeburn Newsgroups: gmane.lisp.guile.user Subject: Re: Now that SCM type is a union... Date: Sat, 13 Aug 2011 01:26:03 -0400 Message-ID: <74643390-9111-4086-B315-1D2F847A514B@raeburn.org> References: <20110812124436.GA2223@ccellier.rd.securactive.lan> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1313213176 3721 80.91.229.12 (13 Aug 2011 05:26:16 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 13 Aug 2011 05:26:16 +0000 (UTC) Cc: guile-user@gnu.org To: rixed@happyleptic.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Aug 13 07:26:11 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 1Qs6jb-0003MM-G5 for guile-user@m.gmane.org; Sat, 13 Aug 2011 07:26:11 +0200 Original-Received: from localhost ([::1]:41934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qs6ja-0000kK-OE for guile-user@m.gmane.org; Sat, 13 Aug 2011 01:26:10 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:55732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qs6jY-0000kE-UC for guile-user@gnu.org; Sat, 13 Aug 2011 01:26:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qs6jX-0003Ss-Ih for guile-user@gnu.org; Sat, 13 Aug 2011 01:26:08 -0400 Original-Received: from mail-qw0-f41.google.com ([209.85.216.41]:58401) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qs6jX-0003Sj-GV for guile-user@gnu.org; Sat, 13 Aug 2011 01:26:07 -0400 Original-Received: by qwa26 with SMTP id 26so2353021qwa.0 for ; Fri, 12 Aug 2011 22:26:05 -0700 (PDT) Original-Received: by 10.224.216.5 with SMTP id hg5mr1235363qab.268.1313213165564; Fri, 12 Aug 2011 22:26:05 -0700 (PDT) Original-Received: from squish.raeburn.org (c-24-128-48-142.hsd1.ma.comcast.net [24.128.48.142]) by mx.google.com with ESMTPS id d12sm2789614qcd.26.2011.08.12.22.26.04 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 12 Aug 2011 22:26:04 -0700 (PDT) In-Reply-To: <20110812124436.GA2223@ccellier.rd.securactive.lan> X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.216.41 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:8707 Archived-At: On Aug 12, 2011, at 08:44, rixed@happyleptic.org wrote: > Between stable-2.0 and master a patch changed the C representation > of the SCM type so that it is now a union. >=20 > This code : >=20 > static SCM foo =3D SCM_UNSPECIFIED; >=20 > now expands to something similar to : >=20 > static SCM foo =3D (SCM) { ... }; >=20 > This form (casting a struct or union initializer while initializing a > global identifier) is for some reason invalid when gcc is called with > "-std=3Dc99" (I was about to say : "was invalid in c99", but who = really > knowns?) nor "-std=3Dgnu99" (although it works when std is set to c89 = or > gnu89). ("Is for some reason invalid" is not very descriptive; please include = specific compiler messages.) 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. The GCC documentation says that a GCC extension permits such = initialization. =46rom 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 wouldn't surprise me if it has to do with how either compound = literals or constant expressions are handled in the compiler making it = hard to support them as both addressable anonymous objects and constant = initializers, and for C99 conformance they'd have to go with the former. = I guess the GCC documentation needs fixing. > I tried to get rid of the cast to (SCM) in tags.h but the compilation > then fails since some code relies on the cast to SCM. Yes, to be used as a value in an expression, rather than an initializer = for a variable, it needs to use the compound-literal syntax with the = parenthesized type name. > So, lets suppose I have an app written in c99 that I want to extend = with > guile, how could I compile it ? 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. Maybe we need a separate = set of macros for static initialization using SCM_UNDEFINED, SCM_BOOL_F, = and friends? 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. Ken=