From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!clyde!cbatt!ihnp4!homxb!houxm!mhuxt!m10ux!mnc From: mnc@m10ux.UUCP (MHx7002 ) Newsgroups: comp.lang.c,comp.lang.ada Subject: How to get Ada private types in C Message-ID: <172@m10ux.UUCP> Date: Mon, 9-Mar-87 12:23:22 EST Article-I.D.: m10ux.172 Posted: Mon Mar 9 12:23:22 1987 Date-Received: Wed, 11-Mar-87 04:47:15 EST Organization: AT&T Bell Labs, Murray Hill, NJ Xref: mnetor comp.lang.c:1218 comp.lang.ada:164 List-Id: One of the important features of Ada that allows the safe implementation of abstract data types is the "private" type feature. You can declare a new type in the specification of a module, but indicate that the details of the type definition may not be seen by users of the module. These users may only declare variables of that type. To perform any operations on the variables, they must be passed as arguments to functions of the module that "owns" the private type. Obviously this is necessary to prevent users of an abstract data type from writing code that depends on the particular current implementation of the type, say as an array. Such a dependency would prevent changing the implementation later. Wouldn't it be nice if the same feature could be obtained in a C header file (which is the analog of an Ada specification)? Well the following program compiles without errors on Berkeley 4.3 and Sys V.2 (VAX versions): typedef struct PRIVATE_S *PRIVATE_P; main() { PRIVATE_P x; if (x) exit(); } If this is legal C everywhere, it implies that one can obtain a private type by declaring it to be a struct pointer in the header file (PRIVATE_P), but only declaring the struct type (PRIVATE_S) in the module that owns the type. Comments? -- Michael Condict {ihnp4|vax135|cuae2}!m10ux!mnc AT&T Bell Labs (201)582-5911 MH 3B-416 Murray Hill, NJ