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 19:05:20 -0500

On 9/20/07, Rob Landley <address@hidden> wrote:

> > 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...

My bad, I've been slogging through the c99 draft, H&S, K&P for the
past few days and trying to translate it into English, and forgot to
disambiguate "static"  The c metalanguage is what is commonly referred
to as "an unholy mess" (static is not the opposite of dynamic, const
is not the opposite of volatile, lvalues are expressions, not values,
"typedef" is a storage class specifier, etc. etc).  When you start
looking closely at it it's kind of amazing the language was
successful.  Must have been a case of "do as I do, not as I say".

Static extent (or is it duration? and why can't we stick to one
metaphor?) and "linkage" (=scope? visibility? huh?) seem to be
distinct; the "static" keyword means static extent + internal linkage
(name not exported to linker; I think that means "local scope");
"extern" means static extent, name exported to linker.  At least I
think that's the idea.
>
> > 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?

Bingo.  A conflation of storage duration and scoping, all rolled into
one unreliable name.  My tentative translation into English:

"static" =>  eternal life + local scope (block, file, etc.)
"extern" => eternal life + proselytizing (projection to containing
scope, either file/TU or global)

by which I mean "extern" is like a name-projection operator (in
contrast to value-projection operators . and ->); it projects a name
into the containing scope, which may be the file, er, translation
unit, when "extern" is used in block scope.  "Static" is of course
utterly misused in c, since it basically means const (in English, I
mean).  Ugh.

> Who named these?

That would be software developers.  ;)_

-gregg




reply via email to

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