From -822202138437144068
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ede379f5dbbc1549
X-Google-Attributes: gidf78e5,public
From: niklasb@my-deja.com
Subject: Re: Suggestion: "typeof" keyword
Date: 1999/08/18
Message-ID: <7pcvjs$tk4$1@nnrp1.deja.com>#1/1
X-Deja-AN: 514097026
X-NNTP-Posting-Host: 131.107.3.75
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>
X-UID: 0000000001
X-Status: $$$T
X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)
X-Http-Proxy: 1.0 RED-PRXY-05, 1.0 x32.deja.com:80 (Squid/1.1.22) for client 131.107.3.75
Organization: Deja.com - Share what you know. Learn what you don't.
X-Article-Creation-Date: Wed Aug 18 00:43:42 1999 GMT
X-MyDeja-Info: XMYDJUIDniklasb
Newsgroups: comp.std.c++
Originator: clamage@taumet


In article <CVJFZFAbaWu3Ew15@robinton.demon.co.uk>,
  Francis Glassborow <francisG@robinton.demon.co.uk> wrote:
>
> [...]
>
> Proponents of 'typeof' should be beginning to get an idea of the
degree
> of detail required for a proposal for such a keyword.  If and only if
> they can provide a sufficiently tight specification some of us would
be
> willing to champion it, but if you want the extension in the next C++
> standard they must do the preliminary work.
>
> [...]

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.

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

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



Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


[ 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              ]




