comp.lang.ada
 help / color / mirror / Atom feed
* Why unknown discriminants for private types?
@ 1996-04-11  0:00 Dale Stanbrough
  0 siblings, 0 replies; only message in thread
From: Dale Stanbrough @ 1996-04-11  0:00 UTC (permalink / raw)


In a previous question on how to force initialization of objects
(c.f. constructors in C++) I have been pointed to using unknown
discriminants on private types.

From the rationale I found...

"A private type can now be marked as having an unknown number of
 discriminants thus 

   type T(<>) is private;

 The main impact of this is that the partial view does not allow
 uninitialized objects to be declared. If the partial view is also
 limited then objects cannot be declared at all (since they cannot
 be initialized). The gives the writer of an abstraction rather more
 control over the use of the abstraction."
 
 
My problem with this is that it seems a rather obscure method to
enforce initialization, compared to a specific pragma. For example...

	type T is private;
	pragma enforce_initialization(T);


which seems much more readable.

As well unknown descriminants precludes the writing of some types,
as type T above is (or at least it's partial view) is unconstrained.
The following is thus illegal...

	package A is
	
		type T(<>) is private;
		
		type List is array(1..10) of T;
		
	private
		...
	end A;


As well a pragma enforce_initialization could be applied to non
private objects.
Certainly such a pragma could be added to any compiler without
affecting the portability of programs using it.


Any comments?


Dale




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-04-11  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-04-11  0:00 Why unknown discriminants for private types? Dale Stanbrough

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