comp.lang.ada
 help / color / mirror / Atom feed
From: mnc@m10ux.UUCP (MHx7002 )
Subject: How to get Ada private types in C
Date: Mon, 9-Mar-87 12:23:22 EST	[thread overview]
Date: Mon Mar  9 12:23:22 1987
Message-ID: <172@m10ux.UUCP> (raw)

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

             reply	other threads:[~1987-03-09 17:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1987-03-09 17:23 MHx7002  [this message]
1987-03-11 18:28 ` How to get Ada private types in C congdon
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