Definitive list of storage classes
Jens Mueller
jens.k.mueller at gmx.de
Mon Apr 16 00:29:39 PDT 2012
Jonathan M Davis wrote:
> On Sunday, April 15, 2012 18:44:27 Jens Mueller wrote:
> > Jonathan M Davis wrote:
> > > I'd like to know which modifiers are considered to be storage classes. The
> > > term seems to be used on a lot more than actually qualifies (including
> > > using the term for the type qualfiers: const, immutable, and shared), and
> > > even the documentation uses it on stuff that I wouldn't have thought
> > > would be considered storage classes, because they have no effect on how
> > > variables are stored or linked (e.g. synchronized).
> > >
> > > Someone asked about it on stackoverflow, and my explanation is not as good
> > > as it should be simply because I can't find a definitive list anywhere:
> > >
> > > http://stackoverflow.com/questions/10150510/what-are-the-storage-classes-i
> > > n-d
> > I would say that static is the only storage class. By default data is
> > thread local and not shared.
> >
> > enum is not a storage class because nothing is stored here (I mean in
> > memory at run time).
> >
> > extern is not a storage class. Because it just says that the symbol
> > needs to be resolved at link-time.
> >
> > lazy says something about time of evaluation not how a variable's memory
> > is stored.
> >
> > out is about parameter passing. Same for ref. So I think ref is not a
> > storage class. If it was I would expect ref a = 10 to be valid code.
>
> TDPL specifically lists ref, in, out, and static as being storage classes. I'd
> fully expect lazy to be for the same reason, and extern is in C, so it
> probably is in D as well.
I tend to leave out the parameter storage classes ref, in, out, and
lazy. I think D has the storage classes static and extern (just learned
why extern can be considered a storage class). And it dropped C's auto
(default storage) and C's register storage class.
> Regardless, I'm not concerned about what any particular person thinks is or
> isn't a storage class. I want to know what is _officially_ a storage class.
> Clearly, Walter and Andrei seem to have a definition in mind, since they talk
> about const, immutable, and shared being type qualifiers rather than storage
> classes, but as far as I can tell, they've never elaborated on what _is_ a
> storage class beyond a few specific ones mentioned in TDPL.
Yes, you're right. Walter and/or Andrei should give a precise
definition. I believe that TDPL is wrong when it says ref and static are
storage classes. Why should one combine parameter passing and storage
classes of data? I follow C's definition.
> > Don't know about scope. I never used it. Is it going to be deprecated,
> > isn't is?
>
> scope on local variables is going away. scope on function parameters isn't.
>
> http://dlang.org/function.html
Thanks for this clarification.
Jens
More information about the Digitalmars-d
mailing list