tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Segmentation fault compiling jslong.c


From: Gregg Reynolds
Subject: Re: [Tinycc-devel] Segmentation fault compiling jslong.c
Date: Thu, 20 Sep 2007 07:32:09 -0500

On 9/20/07, Rob Landley <address@hidden> wrote:
>
> The constant propagation thing is relatively straightforward, the "int
> thingy=printf();" thing I'm not 100% sure about, is that allowed in c99?  I
> know c++ has constructors that run before main() does, can you do something
> equivalent in C?
>
> I note that gcc complains "initializer is not constant" for the attempt to
> initialize a global with "int thingy=printf("");", so I'm guessing it's _not_
> allowed.  But I'd appreciate somebody more familiar with the expected
> behavior here to pipe up, if they can...

According to Harbison and Steele, initialization of a static or extern
int requires a constant expression.  Automatic and register vars can
be initialized with any expression.  Vars with no explicit storage
class default to extern, which implies static.  (5th ed., 4.6.1)  The
c99 draft says "All the expressions in an initializer for an object
that has static storage duration shall be constant expressions or
string literals".  (6.7.8, constraint 4).

-gregg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]