August 28, 2013 Re: [dox] enum specs vs reality | ||||
---|---|---|---|---|
| ||||
On Wed, Aug 28, 2013 at 09:12:44PM +0200, Andrej Mitrovic wrote: > On 8/28/13, Jacob Carlborg <doob@me.com> wrote: > > Yes, it's sometimes usable to be able to declare dummy types like this. Especially now when we have UAD's (User Defined Attribute): > > > > enum foo; > > > > @foo bar (); > > Good tip, I used to use structs for this but I wanted something non-instantiable. Good idea! I also don't like using structs everywhere just for UDA's. T -- MSDOS = MicroSoft's Denial Of Service |
August 29, 2013 Re: [dox] enum specs vs reality | ||||
---|---|---|---|---|
| ||||
Posted in reply to captaindet | On 2013-08-28 17:34, captaindet wrote: > b) what typeof expects/tolerates seems to be a bit of a minefield by > itself. > > enum test = true; > writeln( typeof(test).stringof ); //prints: bool > > enum wtf; > writeln( typeof(wtf).stringof ); //Error: argument wtf to typeof is > not an expression Actually, I previously misread this. This is working as it should. The first declares a manifest constant: enum test = true Is short for: enum bool test = ture; "bool" is the type, "test" is the name. The second declares a new type, where "wtf" is the name of the type. -- /Jacob Carlborg |
August 29, 2013 Re: [dox] enum specs vs reality | ||||
---|---|---|---|---|
| ||||
Posted in reply to captaindet | On 2013-08-28 17:26, captaindet wrote: > enum keyword covers both, enumeration constants and manifest constants. > the specs cover both in one. moreover, they explain that manifest > constants are only syntactic sugar for anonymous enums: > > enum { A = 2, B = 4 } > > is the same as > > enum A = 2; > enum B = 4; The above is short for: enum int A = 2; enum int B = 4; They declare manifest constants, not types. It's the same as: immutable int A = 2; But you can't take the address of "A", which you can if it's declared as immutable. -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation