[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Segmentation fault compiling jslong.c
From: |
Rob Landley |
Subject: |
Re: [Tinycc-devel] Segmentation fault compiling jslong.c |
Date: |
Thu, 20 Sep 2007 17:27:29 -0500 |
User-agent: |
KMail/1.9.6 |
On Thursday 20 September 2007 7:32:09 am Gregg Reynolds wrote:
> 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.
Ok.
> Automatic and register vars can be initialized with any expression.
Both of which can only be local variables.
> Vars with no explicit storage
> class default to extern, which implies static. (5th ed., 4.6.1)
extern implies static?
Hang on, so if I say "extern int thingy;" in a header, and declare a
global "int thingy;" in a .c file, I can't use that "thingy" in another .c
file that #includes that header?
I'm fairly certain that's not the case. I think you have to say "static" if
you want something to be, you know, static.
However, I thought static and extern were diametrically opposed. We may be
talking about something different here...
> 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).
So static storage duration != static keyword applied to a global, limiting its
scope to the current file?
Who named these?
Right, ok, can only initialize globals with constants. Check. I need to add
a new error() case and a return somewhere, and _then_ fix the darn constant
propogation for 64-bit shifts...
> -gregg
Rob
--
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson.
- [Tinycc-devel] Segmentation fault compiling jslong.c, Sanghyeon Seo, 2007/09/18
- Re: [Tinycc-devel] Segmentation fault compiling jslong.c, Gregg Reynolds, 2007/09/20
- Re: [Tinycc-devel] Segmentation fault compiling jslong.c,
Rob Landley <=
- Re: [Tinycc-devel] Segmentation fault compiling jslong.c, Gregg Reynolds, 2007/09/20
- Re: [Tinycc-devel] Segmentation fault compiling jslong.c, Rob Landley, 2007/09/20
- Re: [Tinycc-devel] Segmentation fault compiling jslong.c, Gregg Reynolds, 2007/09/20
- Re: [Tinycc-devel] Segmentation fault compiling jslong.c, Rob Landley, 2007/09/21
- Re: [Tinycc-devel] Segmentation fault compiling jslong.c, Dave Dodge, 2007/09/21
- Re: [Tinycc-devel] Segmentation fault compiling jslong.c, Rob Landley, 2007/09/21
- Re: [Tinycc-devel] Segmentation fault compiling jslong.c, Peter Lund, 2007/09/21
- Re: [Tinycc-devel] Segmentation fault compiling jslong.c, Gregg Reynolds, 2007/09/21
- Re: [Tinycc-devel] Segmentation fault compiling jslong.c, Rob Landley, 2007/09/21
- Re: [Tinycc-devel] Segmentation fault compiling jslong.c, Peter Lund, 2007/09/21