From -5019764343395948158
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ede379f5dbbc1549
X-Google-Attributes: gidf78e5,public
From: Max TenEyck Woodbury <mtew@cds.duke.edu>
Subject: Re: Suggestion: "typeof" keyword
Date: 1999/08/18
Message-ID: <37BB0F13.98A8C6BE@cds.duke.edu>#1/1
X-Deja-AN: 514349123
X-NNTP-Posting-Host: dukcds.cds.duke.edu
Content-Transfer-Encoding: 7bit
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <7nt3vl$1oe$1@nnrp1.deja.com> <7oh7o8$t3f$1@nnrp1.deja.com> <7ol6hi$ej9$2@news.BelWue.DE> <cTiioXAhAwr3Ew$X@robinton.demon.co.uk> <t7d7ww1vrz.fsf@calumny.jyacc.com> <e4DSyfA4ALs3Ew0Q@robinton.demon.co.uk> <t7r9laz5hj.fsf@calumny.jyacc.com> <7oup0a$8g2$1@nnrp1.deja.com> <37B3C2AD.5AB722AE@lucent.com> <37B5A571.449B@wanadoo.fr> <37B908A8.717CAC2C@lucent.com> <CVJFZFAbaWu3Ew15@robinton.demon.co.uk> <7pcvjs$tk4$1@nnrp1.deja.com>
To: niklasb@my-deja.com
X-Accept-Language: en
X-UID: 0000000001
X-Status: $$$T
Content-Type: text/plain; charset=us-ascii
Organization: Duke University, Durham, NC, USA
Mime-Version: 1.0
Newsgroups: comp.std.c++
Originator: clamage@taumet



PLEASE check out the discussion of 'typeof' from September 1997!

niklasb@my-deja.com wrote:
>...
> 
> Ok, here's my first crack at spelling out the rules for
> a "typeof" keyword (without attempting to argue for why
> it's useful). I don't claim to be a language designer, so
> please be gentle when you tear this apart.
> 
> 1 The typeof operator yields the type of its operand.
>   The operand is either an expression, which is not
>   evaluated, or a parenthesized type-id.
> 
> 2 When applied to an expression, the result is the type
>   of the expression (the static type), not the dynamic
>   type of the object returned by the expression.
> 
> 3 When applied to a reference or a reference type,
>   the result is the referenced type. When applied
>   to a constant reference or constant reference type,
>   the resulting type is not constant.

What about 'volatile'?

>   <Example>
> 
>     vector<int> v;
>     typeof(v[0]) a; // int, not int&
> 
>     const vector<int>& cv = v;
>     typeof(cv[0]) b; // int, not const int&
> 
>   </Example>
> 
> 4 The typeof operator can be applied to a function,
>   a function pointer or a function pointer type.

All are expressions, so this only confuses things.

>   <Example>
> 
>     int F();
>     typedef int (*FPtr)();
> 
>     FPtr p0 = F;
>     typeof(FPtr) p1 = F; // function ptr. type
>     typeof(p1) p2 = F;   // function ptr.
>     typeof(&F) p3 = F;   // function ptr.
>     typeof(F)* p4 = F;   // function
> 
>   </Example>
> 
> 5 In the context of a typeof expression, if T is any
>   type then T() denotes a temporary object of that
>   type, even if the type has no default constructor.
>   (The expression is not evaluated, so it does not
>   matter whether the object can be correctly
>   initialized.)

Wouldn't it make more sense to use (T)0, that is cast syntax,
rather than initializer syntax? That would be more consistent
with the argument being an expression. The comment about not
having to be correctly initialized is a useful addition and
needs to be incorporated.

mtew@cds.duke.edu


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




