From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,208279d79d40e7d8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-01 14:26:53 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!not-for-mail From: Dave Thompson Newsgroups: comp.lang.ada Subject: Re: Ada Advocacy. Message-ID: References: X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Mon, 01 Sep 2003 21:26:53 GMT NNTP-Posting-Host: 12.89.139.151 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1062451613 12.89.139.151 (Mon, 01 Sep 2003 21:26:53 GMT) NNTP-Posting-Date: Mon, 01 Sep 2003 21:26:53 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:42042 Date: 2003-09-01T21:26:53+00:00 List-Id: On Tue, 26 Aug 2003 22:20:36 +0100, "Luke A. Guest" wrote: > Not an URL, but something that I and other programmers have always wanted > to do in C/C++/etc. but cannot is the printing of names of variables ;-) > > That's a damn nice debugging feature. It's been a while but I think it's > something like > > declare > test : Integer := 5; > begin > -- I'm really unsure about the overloaded + operator here, like I said > -- it's been a while (around 6 years!) > Write test'Name + " = " + test; > end > Put[_Line] and test'Image. > should send "test = 5" to the console. > > Something like that anyway ;-P Try doing that in C/C++ without a lookup > table :-( > Generating the string label is easy enough in C or C++ using the preprocessor # (stringize) operator -- as well as just writing it out by hand for a fixed value. But the value conversion in C must be coded knowing the data type, e.g.: #define STR(x) #x ... printf (STR(test) " = " "%d" "\n", test ); /* for an int */ /* but %ld for long int, %f for a float or double, etc. */ /* and this doesn't work at all for non-builtin types */ In C++ all builtin types have operator<< predefined, and you can define it yourself for class types (and enums, although those can also default to builtin integers), in which case this always works: ... cout << STR(test) << " = " << test << endl; and can be generated automatically from one variable name like: #define PRINTVAR(x) cout << # x << " = " x << endl; ... PRINTVAR(test) These can also be modified in obvious ways to do other things than stdout, like C sprintf to a buffer or C++ << to a stringstream, display in a GUI messagebox, send via RPC or CORBA, etc. PL/I has a builtin facility to output any variable(s), or all, with names -- PUT DATA -- but cannot be used for any other purpose. Fortran has NAMELIST I/O to do the same thing for pre-chosen groups of variables, which works bit is a bit clumsy for just one. > Another thing that's really useful is being able to declare the range of, > say, an integer variable - and with bounds checking it gets caught at > compile & runtime (depending on whether it's accessed with a constant or > not). > Pascal also does this. C++ doesn't for builtin integer types, but you can write an integer-like class which does, or better a template which generates such (lightweight) classes on demand. Similarly subscripts are not checked for builtin arrays, but can be for stdlib containers like std::vector and for array-like classes that you write or generate from a template. > The only downside to Ada is the amount of work that has to go into a > simple program just to dump out some text (not very good for beginners) to > the console. > > Also meaningful names negates the need for the absolutely disgusting > hungarian notation. > This is equally true of all languages above (and most if not all others) for user names. Although the names in the Ada standard library(s) are with perhaps a few exceptions more meaningfully (and consistently) chosen than in pretty much all other common languages. - David.Thompson1 at worldnet.att.net