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-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!o13g2000cwo.googlegroups.com!not-for-mail From: "Jerry Coffin" Newsgroups: comp.lang.ada,comp.lang.c++ Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) Date: 23 Mar 2005 19:33:19 -0800 Organization: http://groups.google.com Message-ID: <1111635199.732679.10140@o13g2000cwo.googlegroups.com> References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1111607633.301232.62490@z14g2000cwz.googlegroups.com> <1111619568.938415.90010@g14g2000cwa.googlegroups.com> NNTP-Posting-Host: 68.64.130.76 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1111635204 3214 127.0.0.1 (24 Mar 2005 03:33:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 24 Mar 2005 03:33:24 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: o13g2000cwo.googlegroups.com; posting-host=68.64.130.76; posting-account=mZiOqwwAAAC5YZsJDHJLeReHGPXV5ENp Xref: g2news1.google.com comp.lang.ada:9885 comp.lang.c++:46988 Date: 2005-03-23T19:33:19-08:00 List-Id: Jim Rogers wrote: [ ... ] > For instance the following macro can cause some serious problems when > mis-applied: > > #define SWAP(A,B) ((temp) = (A);(A) = (B); (B) = (temp)) > > char s1[30]; > int i; > > SWAP(S1, i); > > In many cases it is safer to define an in-line function than to > define a macro. I don't see a particularly serious problem here -- the code simply won't compile. At the moment you have some syntactical problems and sloppiness that's overlooked by Ada comilers (because Ada is case-insensitive). Even ignoring those, however, it will fail because of a type-difference. To give a concrete example, after (partially) fixing your code above, Visual C++ says: swap.cpp(7) : error C2440: '=' : cannot convert from 'int' to 'char [30]' There are no conversions to array types, although there are conversions to references or pointers to arrays Modulo trivial things like ':=' vs. '=', 'int' vs. 'Integer', etc., I suspect that's on the same general order as you'd expect to see from an Ada compiler given code that attempted to assign an Integer to an array of characters. I think most C++ programmers, however, would tend to agree that in this case you'd generally be better off using std::swap. -- Later, Jerry. The universe is a figment of its own imagination.