Path: utzoo!attcan!uunet!cs.utexas.edu!sdd.hp.com!mips!pacbell.com!pacbell!barn!everexn!grenada!christmas!rtm From: rtm@christmas.UUCP (Richard Minner) Newsgroups: comp.lang.c Subject: Is this a serious abuse of const? Keywords: const, opaque handles Message-ID: <6@christmas.UUCP> Date: 4 Jul 90 04:17:13 GMT Organization: Island Graphics, Sacramento, California Lines: 31 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 {} 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 ||