sizeof, ptrs, lint, portability
cottrell at nbs-vms.ARPA
cottrell at nbs-vms.ARPA
Fri Feb 8 10:55:47 AEST 1985
/*
-) This discussion is getting ugly. I am not a `dedicated amateur hacker.'
I am quite good as a matter of fact. I care a lot about quality code,
more than most people. I will therefore try & wrap this up.
-) I hope that ANSI gets the standard out soon. Please remember we are
a privileged group in that we get to hear many viewpoints, including
such annoying ones as myself. Many people don't even know there will
be a standard. Lots of people work in a vacuum.
-) I am shocked to find out that pointers may be of different sizes, &
may be of a different size than int. This has been true for so long
many people just assumed it. I believe it should be true wherever possible
for the following reason: if a default exists, it should be a useful one.
Defining different sizes for these items gives credibility to the
claim that C is dangerous. Just another accident waiting to happen.
-) Perhaps you forgot some of the attraxions of the language: a terse
language that modelled the machine closely. No stupid booleans.
All those casts are ugly. How are we to convert people to C if they
must put up with all that verbosity? Shouldn't the compiler know?
Okay, automatic casting will help *execution* correctness, but with
the declarations for funxions in another file, the code will still
read the same (casts optional). Mostly noone looks at header files.
-) I apologize for calling (presumably someone's favorite) machines `weird'
or `braindamaged'. Let's say `less capable'. The pdp-11 was a landmark
in machine design. It was byte addressable, had a stack, memory mapped
i/o, an orthogonal instruxion set, and useful addressing modes. The
vax continued this trend. Most micros (all?) are byte addressable.
Most have an address space two to the size-of-register-in-bits power.
Most of the machines designed before this were not byte addressable.
Most of these machines had some very strange glitches. In short weird.
Some minis continued the mainframe trend and only addressed words.
This sort of machine is an inhospitable host for the C language and
some implementations are downright kluges. I claim that they don't
run C but another language I would call `C--'.
-) While you are claiming that it is MY CODING PRACTICES (and evidently
hordes of others, including 4.2bsd & sys III implementors) that are
nonportable, I am claiming that it is THOSE WEIRD MACHINES that are
nonportable. By changing the rules in the middle of the game, you
are depriving me (and others) of the time honored tradition of punning.
I know it is easier to change the language than the machines. I say
don't do it. Why encourage the production of out-dated hardware?
-) I still maintain that assigning zero to a pointer stores an unspecified
number of zero bits. The nil/null ptr is a convention, just like
null terminated strings. We all agree that zero is special because
there is not likely to be real data there. The null ptr is an
out-of-band value. We agreed to represent it in-bound. Still, a piece
of kernel code should be able to pick up the byte at address zero by:
int j; char *p; p = 0; j = *p;
Allowing any other value to actually be stored breaks this. Besides,
SHOW ME A C THAT USES ANYTHING OTHER THAN ZERO ON ANY MACHINE!!!
K&R says of pointer to integer conversions: "The mapping funxion is
also machine dependent, but is intended to be unsurprising to those
who know the machine." I would be surprised at nonzero null ptrs.
-) Guy: if I want the square root of four, I do sqrt(4.0); NO CAST!
-) As for the Honeywell x16 & CDC 17xx which were 16 bit word-addressable
only (I presume a word pointer in one word, one bit representing
left/rite in the second word?) there is another solution, albeit klugy:
put the whole thing in one word & restrict character addressing to the
lower half of the address space. The Varian V7x series (upgraded 620i)
uses this format, altho words can only reference 32k words because
bit 15 is used for indirexion and byte addressing will not indirect.
Yeah, I know, gross. This can be mitigated if they have memory
management. Why would you need 64k words instead of 32k? Hey, it's
finite. Get a bigger machine if you need one.
-) Perhaps I forgot the :-) on my `swapping by xor' article. Like
Guy said, "cute", but not very user friendly.
-) How many of you port what percentage of programs? I thought the
intent of the standard was to not break existing programs. I claim
that the standard should recognize the existing idioms. Languages
are also defined by usage as well as specification. Pretty soon you
will be passing descriptors around instead of objex!
-) I will present (in another article, this one's getting too long)
a good reason for type punning. Stay tuned to this channel...
-) I started out to be reconciliatory; I am unfortunately (for y'all)
more convinced of my position. Eat flaming death fascist media pigs!
*/
More information about the Comp.lang.c
mailing list