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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,f92fbb4a0420dd57 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,f92fbb4a0420dd57 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: some questions re. Ada/GNAT from a C++/GCC user Date: 1996/04/01 Message-ID: #1/1 X-Deja-AN: 145270767 references: <4jlj79$h1k@Nntp1.mcs.net> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada,comp.lang.c++ Date: 1996-04-01T00:00:00+00:00 List-Id: In article <4jlj79$h1k@Nntp1.mcs.net>, Mike Young wrote: >I'd been bemoaning the lack of iostreams in Ada. Would you elaborate (no pun >intended) more on how "&" and 'Image would be used? Well, I'm not sure exactly what you're asking. To print stuff out, you need some procedure that prints text strings, and you need some way to convert whatever you want to print out into a text string. In Ada, 'Image is used to convert simple data types like Integer and Float into human-readable Strings. For complicated data types, you write your own Image function. The "&" operator just concatenates Strings. So to print out some stuff, you write: Put("X = " & Integer'Image(X) & "; and List = " & Image(List)); Where List is a variable of some complicated data structure. This converts X and List to type String, concatenates the whole mess together, and prints it to standard output. Does that answer your question? >Yup. Good practice is not limited by choice of language, I see. :) :-) >The other sad part of function-like macros is safety of side-effects in macro >arguments. ... Indeed. >In spite of this, macros are still the only way to perform some useful tasks. >For example: > >#ifndef _DEBUG >#define assert(a) >#else >#define assert(a) {if (!a) {_assert_fail(__FILE__, __LINE__, #a);}} >#endif > >How would you do this in Ada? I don't know of any way to do that in Ada. However, that's not a huge problem. You indicate a run-time error by raising an exception. You can write an Assert procedure that checks the condition, and raises an exception if False. Any reasonable debugger can tell you what line of code failed, and show you the line of code. And any reasonable debugger can tell the difference between an exception that is handled, with intent to continue executing, and an exception that is unhandled, and is therefore just a bug. - Bob