From: Paul Rubin on 5 Aug 2010 14:10 Lawrence D'Oliveiro <ldo(a)geek-central.gen.new_zealand> writes: > OK, I have a copy of K&R 2nd Ed on a shelf within reach here. Can you point > out some behaviour that C programmers might need to rely on, that is not > specified in that document? C has all kinds of undefined behavior. "Might need to rely on" is not relevant for this kind of issue. Ada's designers had the goal that that Ada programs should have NO undefined behavior. As a famous example of C's underspecification, the behavior of a[i++] = i; is undefined in C99. See: https://www.securecoding.cert.org/confluence/display/seccode/EXP30-C.+Do+not+depend+on+order+of+evaluation+between+sequence+points
From: Britt on 5 Aug 2010 16:35 On Aug 1, 9:34 pm, Albert Hopkins <mar...(a)letterboxes.org> wrote: > On Mon, 2010-08-02 at 01:08 +0200, candide wrote: > > I would propose that in fact most programming languages are implemented > in C. Sun's (Oracle's) Java compiler and runtime are written in ANSI C.. > The core of the Gnu Compiler Collection (which includes C++ and > Objective-C compilers) is written in C. The open-source GCC Ada compiler (GNAT) is written in Ada. The GPL'd compiler source code is available at http://libre.adacore.com/libre/
From: Neil Hodgson on 5 Aug 2010 18:59 Paul Rubin: > C has all kinds of undefined behavior. "Might need to rely on" is not > relevant for this kind of issue. Ada's designers had the goal that that > Ada programs should have NO undefined behavior. Ada achieves this by describing a long list of implementation defined behaviour (Annex M). http://oopweb.com/Ada/Documents/Ada95RM/Volume/m.htm > As a famous example of C's underspecification, the behavior of > > a[i++] = i; > > is undefined in C99. Ada does not define ordering in all cases either. For example the order of elaboration of library_items (essentially the order in which modules are run in the absence of explicit declarations) is defined for GNAT as """ first elaborating bodies as early as possible (i.e. in preference to specs where there is a choice), and second by evaluating the immediate with clauses of a unit to determine the probably best choice, and third by elaborating in alphabetical order of unit names where a choice still remains """ Other compilers use different orders. I just love that "probably". Neil
From: Roy Smith on 5 Aug 2010 19:45 In article <i3e43n$v7c$4(a)lust.ihug.co.nz>, Lawrence D'Oliveiro <ldo(a)geek-central.gen.new_zealand> wrote: > In message <roy-6BCFA7.22564104082010(a)news.panix.com>, Roy Smith wrote: > > > C++, for all its flaws, had one powerful feature which made it very > > popular. It is a superset of C. > > Actually, it never was. Yes, there are a few corner cases where valid C syntax has different semantics in C and C++. But, they are very few. Calling C++ a superset of C is essentially correct. It is certainly correct from the level of a risk-averse development manager deciding if he or she is willing to use C++ for the first time. Fear of the unknown is a powerful deterrent. It's a lot easier to accept something like C++ because "it's just a superset of C, and we've been using C for years". I suspect the same effect contributed to Java's success as well. "Look, it's got curly braces and semicolons. It's just like C!"
From: David Cournapeau on 6 Aug 2010 02:22
On Fri, Aug 6, 2010 at 8:45 AM, Roy Smith <roy(a)panix.com> wrote: > In article <i3e43n$v7c$4(a)lust.ihug.co.nz>, > Â Lawrence D'Oliveiro <ldo(a)geek-central.gen.new_zealand> wrote: > >> In message <roy-6BCFA7.22564104082010(a)news.panix.com>, Roy Smith wrote: >> >> > C++, for all its flaws, had one powerful feature which made it very >> > popular. Â It is a superset of C. >> >> Actually, it never was. > > Yes, there are a few corner cases where valid C syntax has different > semantics in C and C++. Â But, they are very few. Â Calling C++ a superset > of C is essentially correct. This is only true if you limit yourself to C89 (as python seems to do). If you start using C99 (and lot of people do, if only because they don't realize it because gcc is quite relax about it), then almost no non trivial C code is valid C++ in my experience. David |