From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1014db,37e683828bae12e2 X-Google-Attributes: gid1014db,public X-Google-Thread: 1164f8,b0b9a5eaad4ab6eb X-Google-Attributes: gid1164f8,public X-Google-Thread: f8c65,37e683828bae12e2 X-Google-Attributes: gidf8c65,public X-Google-Thread: 1008e3,37e683828bae12e2 X-Google-Attributes: gid1008e3,public X-Google-Thread: 109fba,37e683828bae12e2 X-Google-Attributes: gid109fba,public From: peter@PJM2.newcastle.edu.au (Peter Moylan) Subject: Re: [++] Tight coding Date: 1998/03/02 Message-ID: <6de8o0$kau$1@seagoon.newcastle.edu.au> X-Deja-AN: 329990728 References: <6csl81$rb9@news-rocq.inria.fr> <34F3B7C5.5FD1@earthlink.net> <34F49435.B6307838@hda.hydro.com> <6dbgjv$lg$1@andros.cygnus.com> <888802209snz@genesis.demon.co.uk> Reply-To: peter@ee.newcastle.edu.au Organization: The University of Newcastle Newsgroups: comp.sys.dec,comp.lang.c++,comp.lang.c,comp.lang.modula2,comp.lang.modula3 Lawrence Kirby wrote: >In article > peter@ee.newcastle.edu.au "Peter Moylan" writes: > >... > >>One of my major gripes about C is the strong influence it's >>had on operating systems design. >> >>We have memory segmentation. We've had it for years. What >>we don't have are operating systems that make proper use >>of the segmentation hardware. >> >>It's true that the earliest attempts to introduce segmentation >>were killed off by considerations of hardware cost and speed. >>But those problems were solved some years ago, when the >>80286 first appeared. > >The 8086 and 80286 employ segmentation as a hack to increase memory >address space. It is totally inadequate as a vehicle for providing the >benefits of a true segmented archetecture. You're mixing two things here. The 8086, it is true, did not have hardware segmentation. The 80286 did. It had some shortcomings - e.g. the limit on segment size - but this was still better than no segmentation at all. Some of the shortcomings were removed in the 80386. > >> Once you can get the segmentation >>hardware onto the processor chip, and have some space left over >>for decent-sized caches, you've got the technology to bring >>segmentation to the masses at an affordable cost. > >Perhaps, but it is the x86 archetecture that has given segmentation a bad >name, not any specific programming language. Specifically the 8086. Yes, I agree. Intel tried to say that the 8086 had a segmented address space; the programmers discovered that it didn't; and then companies like Microsoft simply ignored the segmentation hardware of the 80286 and treated it as a pseudo-8086. Subsequently operating systems like OS/2, Windows NT, and Linux used a small subset of the segmentation possibilities, just enough to get a large address space without going all the way towards using true segmentation. What's worse, the majority of 80x86 users are still running DOS shells like Win95, which treat the segmentation hardware like an add-on kludge. The hardware supports true segmentation, the system programmers don't. >>The catch is that you have all those C programmers demanding >>a "linear address space". [...] > >ANSI C is designed to work in a segmented archetecture, it in no way >requires a linear address space. It is invalid in ANSI C to perform >pointer arithmetic beyond the bounds of the current object (except a >one-past-the-end-rule which isn't a major issue). == and != can be used >to compare pointers into different objects but not > >= < or <=. Every >variable you define and every object you allocate with malloc/calloc/realloc >could be placed in a different segment and that would be a valid ANSI C >implementation. The standard was quite carefully crafted to make an >efficient implemenattion of the language possible on a segmented >archetecture. 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.) 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. 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". 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". >>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. 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. I'm going to be flamed for saying this, but I'll say it anyway. The C programming language was good for its time, but it became obsolete somewhere in the 1970s. There are just two reasons why C remains in widespread use today. First, the incredible but growing conservativeness of today's CS instructors who work so hard at protecting their discipline from the heresy of innovation. Second, the fact that it's still possible to make a profit delivering buggy products. -- Peter Moylan peter@ee.newcastle.edu.au