From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8c65,37e683828bae12e2 X-Google-Attributes: gidf8c65,public X-Google-Thread: 1164f8,b0b9a5eaad4ab6eb X-Google-Attributes: gid1164f8,public X-Google-Thread: 1014db,37e683828bae12e2 X-Google-Attributes: gid1014db,public X-Google-Thread: 109fba,37e683828bae12e2 X-Google-Attributes: gid109fba,public X-Google-Thread: 1008e3,37e683828bae12e2 X-Google-Attributes: gid1008e3,public From: bill@cafe.net (Kaz Kylheku) Subject: Re: [++] Tight coding Date: 1998/03/02 Message-ID: X-Deja-AN: 330103613 References: <6csl81$rb9@news-rocq.inria.fr> <888802209snz@genesis.demon.co.uk> <6de8o0$kau$1@seagoon.newcastle.edu.au> NNTP-Posting-Date: Mon, 02 Mar 1998 11:20:39 PST Reply-To: kaz@cafe.net Organization: Internet Direct Newsgroups: comp.sys.dec,comp.lang.c++,comp.lang.c,comp.lang.modula2,comp.lang.modula3 In article <6de8o0$kau$1@seagoon.newcastle.edu.au>, Peter Moylan wrote: >OK, I expressed myself badly. True, the standard says that you shouldn't >perform dirty tricks on pointers. But the standard does _not_ say that >compilers should check for violations, or even that compilers should >issues warnings about doing something stupid. So in practice the >compilers accept questionable pointer arithmetic, and most C compilers >have things like bounds checking disabled by default. They have to, >for at least two reasons. First, that sort of checking is very expensive in >a language like C. (The language rules mean that very little checking >can be done at compile time; they also make it very difficult to detect >pointers that run outside their bounds.) Actually, the extent of the success of the bounds checking GCC project would tend to indicate that such checking is feasible. It is surprising how simple it is and the extent to which it can pin-point errors, and it does this without changing the representation of pointers. The run time hit isn't all that bad either (but you still wouldn't want it in production code, needless to say). It's acceptable for ``smoke testing''. Second, and perhaps more >important, thousands of programmers and project managers would >scream blue bloody murder if a compiler/runtime system enforced those >rules, because it would break 90% of their existing software. That may be true, but how do we now leap to the conclusion that C has influenced operating system design toward ignoring segmentation hardware? That is really the only assertion made in this discussion thread that is worthy of controversy. I think that most programmers and managers would have a positive response to a tool that would catch deep errors. We can't let Dilbert comics completely determine our view of managers and developers. >The rules in the C standard are a token effort at saying "don't make >mistakes, or I'll call you a naughty boy and make you stand in the corner". No, the rules in the C standard exist to enable certain kinds of implementations. Because one may not compares pointers to distinct objects for anything other than exact equality, compilers may be constructed which place objects in separate logical memory segments. Requiring diagnostic capability for a violation of this rule, on the other hand, might place a severe burden on some implementors---at least according to the best collective wisdom of the standard writers. If the C standard allow arbitrary pointers to be compared in arbitrary ways, with well-defined results, such implementations would have difficulty meeting its requirements. >There is absolutely no enforcement built in. In fact, the rules about >bounds violations are simply a disclaimer to protect compiler >developers, so they can say "yes, I know the compiler failed to warn >you of this error, but it's not our fault; the warranty doesn't cover the >sort of software you're writing". It's not an uncommon opinion that undefined behaviors in the language standards are there in order to absolve the compiler implementors of blame for software failure. However, I believe that it is an unrealistically cynical opinion. The real reasons are that by leaving certain aspects of the language undefined, implementors have more choices as to how something should be implemented. Also, we have to remember that the C language was in widespread use before it was standardized, for better or worse. Sometimes the most ridiculous and easily diagnosable aspects are undefined. For example, if, in a string or character literal, a backslash is followed by something that isn't a valid escape sequence, the behavior is undefined. It's obvious that this is trivial to diagnose, but there is probably a good reason why a diagnostic is not required. The C language has had only one standard approved by ISO so far, and is nearing the completion of a second. As time goes on, we can expect at least some parts of the language to ``tighten up''. But the first standard had to be workable in the way of reflecting existing practice. >>>Perhaps you hadn't noticed the newsgroups to which this was >>>cross-posted. Most of us are already doing a lot better >>>than C. >> >>You don't appear to know C well enough to make that judgement. > >You're probably right, people have been telling me that for the >last 25 years. But the software I produce - using C among other >languages - works, and it's delivered on time and within budget. >(Not many developers can make that claim.) So I think I'm >entitled to an opinion. > >Furthermore, I have continued to resist the modern practice of >charging an "upgrade" price for bug fixes that are delivered a >year late. That's hard to do if the bug fixes are not well separated from genuine enhancements that were also done to the software. There is a difference between a genuine upgrade and strictly bug-fix patches done to the older release. If the software you are getting includes many enhancements that you want as well as bug fixes, what are you paying for? In one sense, you are paying for everything the developer does; including support, marketing, sales. Should you also object that part of the price you pay goes to paying the developer's receptionist, and marketing staff, or office rent? I believe in free bug fix patches; it's hard to disagree with such a policy, because it is based on well-founded ethical principles. The developer should put in as many bug fixes into the older version of the software as possible and make that available to the end user as an alternative to the upgrade option, but it's almost inevitable taht some problems will only be resolved in an upgrade. Sometimes only a design change can resolve some problems, or the bug fix came about as a result of a complete rewrite of some subsystem which can't be retrofitted into the old version for whatever reasons. >Just recently, a builder came to my house and repaired an error >made by one of his carpenters. He didn't charge me, because >the error was his responsibility. In practically every industry, fixing >the bugs is part of the original contract price. If the same idea was >accepted in the software industry, the use of bug-prone programming >languages would disappear overnight. If things are so rosy outside of the software industry, why do there exist ``home owner protection'' type insurance schemes? ;)