trying to simplify an algorithm

Bennett Todd bet at
Tue Mar 1 08:06:58 PST 2005

2005-03-01T15:33:10 Hui Zhou:
> However, in C, pointer is integer, another feature sometime frowned 
> upon.

No, it isn't. Neither is char integer, neither is float integer.
They can be _cast_ to integer, and on machines where sizeof(pointer)
== sizeof(integer) the cast is often lossless and bi-directional,
but pointers are quite definitely not integers. Not only are they
distinct from integers, pointers to distinct types are themselves
distinct types, i.e. a pointer-to-char is not the same type as
pointer-to-float. pointer-to-void is a special placeholder type
that's available as a neutral, common pointer type; it must be cast
to pointer-to-some-real-type before dereferencing (or related
operations like adding an integer offset), but it's guaranteed safe
to cast to any real pointer type; that's why it's the return type
for malloc(3).

If you get into the habit of compiling always with -Wall, gcc does a
reasonable job of informing you about type bugs at compile time.

I can't believe I'm spewing on about this, I haven't used C
significantly in over a decade. Way back in the late '80s I was a
pretty knowlegeable C programmer, though, before I got old and fat
and lazy and shifted to Perl.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <>

More information about the lfs-chat mailing list