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: 103376,4873305131bf4d94 X-Google-Attributes: gid103376,public X-Google-Thread: 1014db,4873305131bf4d94 X-Google-Attributes: gid1014db,public X-Google-Thread: 109fba,4873305131bf4d94 X-Google-Attributes: gid109fba,public From: seebs@plethora.net (Peter Seebach) Subject: Re: Porting (was ADA and Pascal etc) Date: 1997/10/31 Message-ID: <63d3sm$ap7$3@darla.visi.com>#1/1 X-Deja-AN: 286214608 References: <34557f2b.1934172@news.mindspring.com> <63bhta$g2e@bgtnsc03.worldnet.att.net> <345AB871.413A@dynamite.com.au> X-Complaints-To: news@visi.com X-Trace: darla.visi.com 878318294 11047 205.166.146.1 (31 Oct 1997 17:18:14 GMT) Organization: Plethora Internet Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++ Date: 1997-10-31T00:00:00+00:00 List-Id: In article <345AB871.413A@dynamite.com.au>, Alan E & Carmel J Brain wrote: >May I respectfully offer a counterexample? If you don't mind us making fun of you. You posted an incorrect C++ example without including comp.lang.c++. >Code Warrior accepts >void Main() Does it? Traditionally, C has used a lower case M on main, and I seem to recall that the Mac implementations were case sensitive. C++ likewise. Further, if it accepts it at all, it does so out of bemused tolerance for your misguided efforts, in both C and C++, main is a function returning int, not void. >{ > for (int i ; i < SomeValue ; i++ ) > { > // Do something > } Well, this is certainly C++; C doesn't let you declare things in the first expression of a for, and uses /*...*/ for comments. > for (int i ; i < SomeOtherValue ; i++ ) > { > // Do something else > } >} >As by one reading of the (yet-to-be-standardised C++ spec) the scope of >each >i is limited to reside within the parens {} of each loop. Your problem here is that C++ is random. There have been holy wars fought among the faithful over whether i's scope should end at the end of the loop (those aren't parens, btw, they're braces), or should continue into the surrounding code. The "rationale" (hah!) given by the "surrounding code" fanatics is for (i = 0; i < 20; ++i) if (condition) break; - they want to be able to see whether or not i made 20 I don't honestly know, or care, which of these C++ has officially settled on; I know that there's been a lot of debate, and it's been both ways. C9X, of course, has the scope end with the end of the for; if you want i to scope beyond the for, declare it outside the for. >I do not consider the above code to be "trash". If you do, please >elucidate as to why (heck, I could be wrong, have been before, will be >again) As C, it's trash in more ways than I can conveniently enumerate. As C++, it's trash because: You misspelled and misdeclared main You depended on a not-standardized feature This is stupid. When you are working with a pre-standardized language, with implementations which may be tracking the standard to different degrees, you *NEVER* push the envelope. >The above code isn't exactly platform specific, is it? The problems with >porting any language isolates and contains. No, it's in things like the >STC library, where CodeWarrior 9 accepts instantiation of a vector of >objects for which the '<' operation isn't defined, providing you never >try sorting, whereas MVC++ 5 doesn't. But IIRC MVC++ 4 does. Ahh. So, what you're saying is that C++ is not yet standardized, and you can't be sure where in the process a compiler is. Pray tell, what would you have said to someone having similar problems with "Ada 95" compilers in 1992 or 1993? >To recapitulate: often (not always, but more times than not) a port of >Ada crossplatform requires only recompilation. Port from compiler to >compiler ditto, >but more so. I have yet to see such a thing when porting C++. I've seen >it once in C, because we had a pre-compiler that heavily massaged the >source code first ( a diff showed about 5% difference) Drop by my web page; all of my non-POSIX-dependant C is expected to compile and run correctly on all C compilers. All of them. No exceptions. I consider any failure to do this a bug, and will happily fix it. Yes, I really mean it. I do know of systems that won't run the code correctly; none of them make even a convincing claim of being C89 compilers. >Try having a go at the lovelace Ada tutorial at http://www.adahome.com . >You may hate it, of course. But it also may give you insights into how >to code C and C++ better. IMHO it's worth a look for any C programmer >anyway, just as all Ada programmers should be exposed to C { if only to >beef up their resistance :) } I probably will. Learning multiple natural languages makes you more literate, fluent, and expressive in your native tongue, and I believe the same goes for programming languages. Familiarity with other idioms can help you see a way around a sticky problem. -s -- seebs@plethora.net -- Speaking for myself. No spam please. Copyright 1997. All rights reserved. This was not written by my cat. C/Unix wizard - send mail for help! -- - More Net, Less Spam!