Topic: An Implementation of __declare


Author: sdonovan@mweb.co.za (Steve Donovan)
Date: Thu, 7 Nov 2002 17:50:35 +0000 (UTC)
Raw View
Some years back  Ramon Garcia Fernandez
proposed a new C++ keyword, __declare, in this forum:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=slrn82opje.lj1.ramon%40jl1.quim.ucm.es&rnum=1

__declare uses the implied type of the initializing expression
to declare a variable. This is useful where the implied type
is complicated, or not known explicitly:

__declare i = 10;           // i is int
__declare li = ls.begin();  // li is list<list<int>>::iterator
...
inline __declare sqr(double x) { return x*x; }

Note that qualifiers are stripped from the initializer type,
on the principle that they can be added later. This is
a valid use of __declare:

const __declare i = 10;

I have done a straightforward implementation of __declare in
the UnderC C++ interpreter, and it's an entertaining feature.
It's particularly useful in informal, interactive work:
;> #define let __define
;> let x = 2.3;
;> let pg = uc_global();       // type XNTable*
;> let xe = pg->lookup("x");   // type XEntry*

As for more formal production code, I can't say. It could lead
to a style in which most variable types were implied and code
was hard to maintain.  (Although an intelligent language environment
could certainly keep track of variable types.)

We would get some of the benefits of 'typeless'
languages like Python without the nasty downside (slow and unsafe).

Steve Donovan.
(http://home.mweb.co.za/sd/sdonovan/underc.html)

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: francis.glassborow@ntlworld.com (Francis Glassborow)
Date: Fri, 8 Nov 2002 15:25:52 +0000 (UTC)
Raw View
In article <8b93687e.0211070911.1fb72669@posting.google.com>, Steve
Donovan <sdonovan@mweb.co.za> writes
>Some years back  Ramon Garcia Fernandez
>proposed a new C++ keyword, __declare, in this forum:

Perhaps you might like to check out the paper recently presented to the
evolution group of WG21 by Bjarne Stroustrup re new uses for auto, and
the introduction of typeof. I do not have the reference to hand but you
experience with implementing __declare might be useful.


--
Francis Glassborow      ACCU
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]