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,LOTS_OF_MONEY autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1cf653444208df72 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-09 10:35:51 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cyclone2.usenetserver.com!usenetserver.com!news01.optonline.net!news02.optonline.net.POSTED!not-for-mail From: "Mike Mohr" Newsgroups: comp.lang.ada References: <9pgr68$7pu1@news.cis.okstate.edu> <9phnic$9g5$1@nh.pace.co.uk> <5fkv7.134136$w7.19988807@news02.optonline.net> <9pski60j31@drn.newsguy.com> Subject: Re: ada vs. cpp X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: Date: Tue, 09 Oct 2001 17:35:50 GMT NNTP-Posting-Host: 24.188.177.13 X-Trace: news02.optonline.net 1002648950 24.188.177.13 (Tue, 09 Oct 2001 13:35:50 EDT) NNTP-Posting-Date: Tue, 09 Oct 2001 13:35:50 EDT Organization: Optimum Online Xref: archiver1.google.com comp.lang.ada:14065 Date: 2001-10-09T17:35:50+00:00 List-Id: "Ted Dennison" wrote in message news:KZEw7.21653$ev2.29994@www.newsranger.com... > In article , Mike Mohr says... > > > >Since we are discussing orthogonal language features > >which constitute string defects if not present, how > >do I explicitly pass Ada strings by value or reference? > > Since its fairly easy for the compiler to figure out which will be more > efficient at compile time (which is what Ada does), the only reason you would > need for doing this would be if you want to do it *less* efficiently. Odly, > noone has really found that need that I have heard of. :-) I don't believe Ada needs a specific pass-by-value or pass-by-reference mechanism, and I don't think C++ strings a better than Ada strings. I was just playing along ;) It isn't strictly necessary for a C++ programmer to have the identical facilities available to an Ada programmer to complete a task. My examples showed this (yet challenges continue :). I would rather see high level comparison between implementations which make heavy use of string operations. Then one could get an idea of how complex, how readible, and how efficient each version is. Speaking of high level comparisons, I would really like to see how Ada does in the great language shootout. http://www.bagley.org/~doug/shootout/ I don't have the skill level in Ada to do it justice but perhaps someone in this newsgroup can give it a try. > Well, there is one other use: in interfacing to external routines. That's where > Ada's interface support comes in. > > I'm curious how you think you do this in C++ though. An array of chars is > essentially a pointer, and thus will always get passed by reference no matter > what you do. "string" is an opaque type defined in the STL almost certianly > using pointers, and is thus in the same boat. So how do you force value? That is an interesting question. Typically, in C++ copy by value is done on an any invocation of the copy constructor. One could argue that reference counted implementations (or COW) may not do actual copies, despite the fact that a copy constructor is invoked. In such cases copy by value is only deferred until the point that a condition arises which forces a write, given the value semantics originally specified. For example in this call function(V1); void function(string arg); { arg[4] = 'a'; cout << arg; } A value copy of V1 must be made, the only thing that is indeterminate is at what point that copy occurs. It is a peculiar footnote that the allowance for COW string implementations in C++ led to a subtle bug in the language specification which led to a call by some to ban the mad cow :) Since C++ operates on an abstract machine any non-detectable behavior may be elided and I will venture to guess that the same is true for Ada. This kind of language implementation transparency is common but it does not invalidate the semantics of commands or their value when used in ordinary programs.