x.sizeof vs typeid(x)

Moritz Warning moritzwarning at _nospam_web.de
Wed Feb 6 19:18:14 PST 2008


On Wed, 06 Feb 2008 18:51:49 -0800, Walter Bright wrote:

> Sergey Gromov wrote:
>> I wonder why .sizeof is implemented as a property while typeof() and
>> typeid() are functions.  I can see no reasons for such inconsistency.
>> It's not that obvious for typeof() because it yields a type instead of
>> a value, but even then, why not ?
> 
> Because expression.identifier always yields an expression, whereas
> typeof() always yields a type. It makes parsing easier and more
> consistent.

>From a users perspective, my first thought is always that it should be 
used similar to a type alias in a struct/class.
.typeof feels also more consistent with .length, .sizeof or .stringof.

typeof() looks like a build-in compile time function, but the feeling to 
access the AST is definitely nicer.

Thought, I don't know if typeof() is worth the gains on the parsing side.



More information about the Digitalmars-d mailing list