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: 1014db,4873305131bf4d94 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,4873305131bf4d94 X-Google-Attributes: gid103376,public From: kaz@helios.crest.nt.com (Kaz Kylheku) Subject: Re: Porting (was ADA and Pascal etc) Date: 1997/10/31 Message-ID: <63d5l4$tub$1@helios.crest.nt.com>#1/1 X-Deja-AN: 286236748 References: <34557f2b.1934172@news.mindspring.com> <63bhta$g2e@bgtnsc03.worldnet.att.net> <345AB871.413A@dynamite.com.au> Organization: A poorly-installed InterNetNews site Newsgroups: comp.lang.ada,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: >> Sounds like you may have been a victim of the run of your patients. >> Well written C code is very portable. I've seen compiler upgrades >> break code, but only because it was trash to begin with. > >May I respectfully offer a counterexample? >Code Warrior accepts > >void Main() >{ > for (int i ; i < SomeValue ; i++ ) > { > // Do something > } > > for (int i ; i < SomeOtherValue ; i++ ) > { > // Do something else > } >} This isn't C. No conforming ANSI C compiler can accept the above external function definition without diagnosing at least one syntax error. You are confusing C++ with C. Do not attribute your C++ porting headaches to the C programming language. C++ isn't even standardized yet, and compilers for that language differ in their level of incorporation of the latest draft features. On the other hand, the 1989 ANSI standard for the C language was approved by ISO in 1990. I find that the level of conformance in C compilers tends to be very good. C++ is a ``moving target'' on the other hand. It annoys me that the C language gets a ``bad rap'' due to C++. C++ should never have happened. Stroustrup should have done BCPL with Classes, Fortran with Classes or Pascal with Classes. What's even more annoying is people who can't recognize that C and C++ are distinct languages, that there is no such language as C/C++, and that the set of C++ programs is not a superset of the set of C programs. Everytime I see C juxtaposed with C++ with an intervening slash, I cringe. >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. Yes, they C++ committee finally seem to have sorted out this trivial issue. What's worse is that mixed declarations and statements are likely going to be part of the new C language. Ada makes so much more sense by requiring data declarations to precede the function body. Only scatter-brained programmers see a stylistic advantage in declarations interspersed with statements. It's perhaps a remnant of brain damage inflicted by programming in BASIC. I try to even avoid declarations at the beginnings of nested blocks, even though C allows it. It's not necessary. I think that the following form would have been great for C function definitions: int main(int argc, char **argv) /* formal parameters */ int x; /* locally scoped declarations */ double y; static char z = 'z'; extern float w; { /* body, no declarations allowed anywhere */ } This obviously borrows from the old-style declaration syntax in which parameter types were declared just before the opening brace of the function, and only their identifiers were named in the paramter list. Here, parameters are fully declared in the parenthesized parameter declaration list, and the declarations that precede the opening brace are for locals, like a VAR block in Pascal. In my opinion, this would make a much nicer language, and is something to consider by anyone who wants to invent a language with a C-like syntax. >Yet MVC++ 5 barfs: as the scope of i is deemed to be within the main >program, so the two int i declarations clash. > >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) I consider it to be trash by definition, because C++ is trash. :) >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 went through it a while ago. It's a good tutorial. (I don't think that this beginner tutorial will help anyone write better C, though! :) On the other hand, I find that the Ada95 standard doesn't make a great reference manual, unfortunately! The ISO 9899-1990 standard for C is so much more readable (for the most part). Ada95 needs to be revised and typeset a little better. Because it's freely available, it discourages an independent author from writing a clear reference manual targetted at the working programmer. -- "In My Egotistical Opinion, most people's C programs should be indented six feet downward and covered with dirt." -- Blair P. Houghton