comp.lang.ada
 help / color / mirror / Atom feed
From: congdon@ci-dandelion.UUCP
Subject: Re: How to get Ada private types in C
Date: Wed, 11-Mar-87 13:28:21 EST	[thread overview]
Date: Wed Mar 11 13:28:21 1987
Message-ID: <513@ci-dandelion.UUCP> (raw)
In-Reply-To: 172@m10ux.UUCP

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		

  reply	other threads:[~1987-03-11 18:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1987-03-09 17:23 How to get Ada private types in C MHx7002 
1987-03-11 18:28 ` congdon [this message]
1987-03-12  8:22   ` chris
1987-03-18  1:25   ` Bob Dietrich
  -- strict thread matches above, loose matches on Subject: below --
1987-03-11  7:50 bzs
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox