comp.lang.ada
 help / color / mirror / Atom feed
* How to get Ada private types in C
@ 1987-03-11  7:50 bzs
  0 siblings, 0 replies; 5+ messages in thread
From: bzs @ 1987-03-11  7:50 UTC (permalink / raw)



Yes, your program certainly works, amazing what people will find,
very interesting.

One problem is, try:

	printf("%d\n",sizeof(x));

in the test program. I get an Unknown size error on the compilation.

This leads me to believe that although you could do something with
this it's probably just exploiting a missing error check in the
compiler caused by the need to "trust" forward references to struct
pointers or something like that. A bug I guess.

Ooops, that was on a SUN3. My Encore just barfs all over your original
example (I'm pretty sure they're using a green hills compiler, not a
pcc derivitive.) I think the ice is getting very thin.

	-Barry Shein, Boston University

^ permalink raw reply	[flat|nested] 5+ messages in thread
* How to get Ada private types in C
@ 1987-03-09 17:23 MHx7002 
  1987-03-11 18:28 ` congdon
  0 siblings, 1 reply; 5+ messages in thread
From: MHx7002  @ 1987-03-09 17:23 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1987-03-18  1:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1987-03-11  7:50 How to get Ada private types in C bzs
  -- strict thread matches above, loose matches on Subject: below --
1987-03-09 17:23 MHx7002 
1987-03-11 18:28 ` congdon
1987-03-12  8:22   ` chris
1987-03-18  1:25   ` Bob Dietrich

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