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=2.1 required=5.0 tests=BAYES_05,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!husc6!necntc!ci-dandelion!congdon From: congdon@ci-dandelion.UUCP Newsgroups: comp.lang.c,comp.lang.ada Subject: Re: How to get Ada private types in C Message-ID: <513@ci-dandelion.UUCP> Date: Wed, 11-Mar-87 13:28:21 EST Article-I.D.: ci-dande.513 Posted: Wed Mar 11 13:28:21 1987 Date-Received: Thu, 12-Mar-87 21:45:15 EST References: <172@m10ux.UUCP> Reply-To: congdon@ci-dandelion.UUCP (Robert M. Congdon) Organization: Cognition, Inc., Billerica, MA Xref: utgpu comp.lang.c:1230 comp.lang.ada:168 List-Id: In article <172@m10ux.UUCP> mnc@m10ux.UUCP (MHx7002 ) writes: >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? I'm not sure if this is 'legal' C or not (any comments from the language lawyers?) but lint (with -h switch) will warn about the missing definition for 'struct PRIVATE_S'. The structure tag construct is intended to allow definition of self-referential or forward-referencing struct types (K&R pg. 197). For example: typedef struct Foo { struct Foo *next; /* other stuff ... */ } FOO; But in such cases the struct type is eventually defined so the compiler shouldn't complain. In your example, since the compiler never sees a definition for the struct type it's reasonable for the compiler (or lint) to warn about the missing struct type. Pascal allows usage of a pointer types in type definitions before the base type of the pointer type has been defined for self-referential types as well. In fact, I think that this is the only example of 'usage before definition' in Standard Pascal (where even labels have to be pre-defined!). -- Robert M. Congdon UUCP: {talcott,vaxine,mit-eddie}!ci-dandelion!congdon Cognition, Inc. PHONE: (617) 667-4800 900 Tech Park Drive Billerica, MA 01821