one of the first thing I noticed compiling in plan9 is that arithmetic on void* is illegal.

That’s what the standard says.

While Plan 9 C doesn’t pretend to be compliant, the core language does roughly match C89 with a few C99 extensions.

Other compilers treat void* as uchar*. Conceptually, it makes sense. A pointer to void doesn't point to any object. But then I've seen the use of void* in functions (like memccpy) when the pointed object is going to be processed as a byte array. Local uchar*'s are used to do the trick inside the function.

It wouldn't make more sense to avoid the use of void* and just use instead uchar* or better still u8int*?

(Those are different. On Plan 9, we do make (too many) assumptions about type sizes, but conceptually, a byte need not be limited to eight bit.)

I’m now quoting the C99 Rationale (revision 5.10).

Page 37, § 6.2.5:

A pointer to void must have the same representation and alignment as a pointer to char; the intent of this rule is to allow existing programs that call library functions such as memcpy and free to continue to work.

Page 48, § 6.3.2.3:

The use of void* (“pointer to void”) as a generic object pointer type is an invention of the C89 Committee. Adoption of this type was stimulated by the desire to specify function prototype arguments that either quietly convert arbitrary pointers (as in fread) or complain if the argument type does not exactly match (as in strcmp).

--
Humm

------------------------------------------
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Tecaea3b9ec8e7066-Me2a3b163527df44b207e4fc3
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

Reply via email to