defines both a type and a subtype

V

valtih1978

Every type declaration in LRM says that it defines "both a type and a
subtype". What is the idea of that? Why not to define the constrained
type right away?
 
A

Andy

Every type declaration in LRM says that it defines "both a type and a subtype". What is the idea of that? Why not to define the constrained type right away?

Ok, this has to do with integer, physical and real types, not all types.

The two types allow implicit conversion from mumeric literals, defined onlyfor the anonymous type, to any declared type (really an implicit subtype) of that anonymous type. However, unlike explicit subtypes of the same explicit type, you cannot implicitly convert between implicit subtypes.

type his_real is range 0.0 to 1.0; -- implicit subtype of universal_real
type her_real is range 0.0 to 1.0; -- another implicit subtype of universal_real

variable his : his_real := 0.5; -- both are compatible with anonymous literals
variable hers : her_real := 0.5;

his := hers; -- ERROR! but you can't do this!

However, if you declared his_real and her_real as named subtypes of real, then you could assign from one to the other.


Andy
 
V

valtih1978

What this has to do with my question? I ask why the declaration cannot
just define a new type. You say that this is done to make the
declarations incompatible on the ground that explicit subtypes are
compatible. But my question is why to do the subtyping in the first
place in the declaration? If I just introduce a single type, without
subtypes, his and her variables can also be defined compatible with the
literal but not with each other.

It is stupid IMO to introduce implicit subtyping. It is even more stupid
to introduce a special rule that matches implicit subtypes differently.
So you defend one stupid rule by introducing another. Is it ok?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top