Explanations

COTTRELL, JAMES cottrell at nbs-vms.arpa
Wed Nov 20 12:21:37 AEST 1985


/*
> Ron Natalie has already replied restrainedly (for him) to this fool's
> posting, so I will simply FLAME HIM for CONFUSING THE POOR NOVICE by
> providing MISINFORMATION about what C type casts do.  Dennis Ritchie
> about a year ago made one of his rare appearances in this newsgroup
> to set this matter straight, and it is covered quite well in all the
> standard references for C.

Okay, Doug. Roll away the dew. Sez you:
 
> A type cast has the same semantics as assignment to a temporary
> variable of the same type as the cast and use of that variable
> thereafter in the embedding context.  In particular, this means
> that (gleep *)0 is a proper null pointer to a thing of type `gleep';
> this is because assignment of the integer constant 0 to a pointer
> has those semantics.

Hey, isn't that what Ron just said? I quote:

" I don't know how many times you have been over it, but casts do change the
" bit pattern of what they apply to, if necessary.
" Let's take out our copies of Kernighan and Ritchie, turn to page 42 and
" read aloud:
" 	"The precise meaning of cast is in fact as if expression were
" 	 assigned to a variable of the specified type, which is then
" 	 used in place of the whole construction"
" 

> There is no assumption whatsoever about "bit
> patterns" in any of this!

Probably not. But Ron was debunking this guy's pet theory which 
specifically mentioned bit values. Speaking the other guy's language.

" > The ONLY totally correct thing to do if machines with non-zero nulls
" > are involved is to assign 0 to a pointer variable, and then pass the var.
" > So if you want to be totally correct you would define NULL like this:-
" > 
" > #define NULL	(___p=0)
" > static char *___p;
" 
" This would be exactly the same as casting 0 to (char *) without the
" side effect of loading ___p, BY DEFINITION.

> I try to be polite (for me) in these postings, but this yo-yo has
> done a disservice to those readers who do not already know the C
> language quite well and who might therefore think that he knows
> what he's talking about.

Yeah, not to mention we gotta read it ONCE AGAIN!
I'm sure Ron doesn't need my help defending himself, and you two are
probably in closer agreement with each other than myself, but I would
have to say he done goodly.
 
> To repeat the CORRECT information that I originally posted, so that
> the novice is not left with any misconceptions on the matter:

Either none, or *all* of them :-)

	jim		cottrell at nbs

Some come to cast their lint away
Some come to fake it just one more way
					with apologies to Jerry
*/
------



More information about the Comp.lang.c mailing list