Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] C puzzle
- Date: Wed, 31 Jul 2002 09:53:16 +0900
- From: "Norman Diamond" <ndiamond@example.com>
- Subject: Re: [tlug] C puzzle
A few random comments are in order. (1) Once upon a time, C was an improved assembly language, with portable SYNTAX but symantics which varied from machine to machine since it was doing machine operations. Somewhere along the line this idea went away. Even one of the inventors of C changed with the trend of making C a portable LANGUAGE, so that applications could be written in the new C and have similar behavior on many machines, but individual machine characteristics were no longer reflected in the new C. Since 1989, there have been standard definitions for what makes C programs correct to varying degrees. None of these definitions is actually correct enough for practical use, not like some other language standards do, but still some things are far enough over the line one way or another to be clearly correct or incorrect on site. Since 1989, what makes a program correct is not whether it luckily happens to produce the desired effect during one execution under one implementation on one machine. (2) Dereferencing a null pointer is clearly incorrect. An implementation is allowed to do things other than crash, it is allowed to print 20 minus signs. One rather famous implementation, which makes this posting almost on-topic, validly exec'ed rogue when it found a #pragma, and it would be equally valid if it exec'ed rogue when it found a program dereferencing a null pointer. (3) If a crash is desired, the abort function is pretty well defined to do it. The crash doesn't have to resemble other kinds of crashes, but it's the closest thing we have to a guarantee of getting a crash. (4) Someone asked for the shortest program that compiles, not the shortest that executes. Again with the standard being somewhat inadequate in its definitions of correctness, there is no guarantee that the following program will compile, but clearly it is correct in some sense: int i; But if you want the shortest that executes, then I agree with a solution that someone else already posted, again with the caveats that the standard doesn't define correctness well enough to guarantee that it would execute. The null program is allowed to be compiled, but is rather clearly wrong because the standard requires a translation unit to include at least one definition of a something-or-other. If anyone here remembers the days when I used to follow the C standard pretty closely (e.g. in comp.std.c), this message now might show how far I've been away from it for the past 3 years. Sorry. Some days I have real work to do, so I don't have time to keep up with things that could have benefited the industry if the industry would have allowed it. -- Norman Diamond
- Follow-Ups:
- Re: [tlug] C puzzle
- From: Viktor Pavlenko
Home | Main Index | Thread Index
- Prev by Date: [tlug] Re: Mutt complaining of a read-only mailspool
- Next by Date: Re: [tlug] Re: ISDN connection woes
- Previous by thread: [tlug] C puzzle
- Next by thread: Re: [tlug] C puzzle
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links