Is this a serious abuse of const?

Richard Minner rtm at christmas.UUCP
Wed Jul 4 14:17:13 AEST 1990


I've been doing some work with what I'll call "semi-opaque handles"
using the following construct (in principle):

#ifdef INTERNAL
#    define C_const__
#else
#    define C_const__	const
#endif

typedef C_const__ struct handle {<stuff>} handle;

The handles are created internally and a pointer is returned to
the 'client' code.  The idea is that the client code has 'read
only' access while the internal code has read/write access.

I've read the ANS (Dec 7, 1988, including the Rationale) carefully
and it appears that this may be a very naughty thing to do.  In
particular, I can imagine some very clever hardware/compiler
handling const objects such that my client code would have
serious problems reading my 'read only' members.  So:

1. Is this really something to worry about?
2. Are there other reasons not to do this thing?
3. From 0 (ugly hack) to 10 (elegant construct), how does this rate?

(Note that I can always "switch if off" if I run into trouble, and
yes I've heard of C++.  Maybe next year.)

-- 
Richard Minner  || {uunet,sun,well}!island!rtm     (916) 736-1323 ||
                || Island Graphics Corporation     Sacramento, CA ||



More information about the Comp.lang.c mailing list