Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > defines both a type and a subtype

Reply
Thread Tools

defines both a type and a subtype

 
 
valtih1978
Guest
Posts: n/a
 
      11-13-2012
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?
 
Reply With Quote
 
 
 
 
Andy
Guest
Posts: n/a
 
      11-13-2012
On Tuesday, November 13, 2012 10:56:36 AM UTC-6, valtih1978 wrote:
> 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
 
Reply With Quote
 
 
 
 
valtih1978
Guest
Posts: n/a
 
      11-14-2012
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

On 14.11.2012 1:51, Andy wrote:
> On Tuesday, November 13, 2012 10:56:36 AM UTC-6, valtih1978 wrote:
>> 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 only for 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
>


 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      11-14-2012
Oh, I forgot who you were. I refuse to argue with you.

Andy
 
Reply With Quote
 
valtih1978
Guest
Posts: n/a
 
      11-15-2012
On 14.11.2012 20:01, Andy wrote:
> Oh, I forgot who you were. I refuse to argue with you.
>
> Andy
>


yes, I like the logic and reason in the argument
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WCF: why both <serivce> and <client> tag defines endpoint? Ryan Liu ASP .Net 1 08-01-2010 06:08 AM
type/subtype definition in entity zhangpei@gmail.com VHDL 3 04-17-2007 11:22 PM
How to define a define that defines some defines ? theotyflos C Programming 3 02-19-2004 05:07 PM
NetFlow & ICMP type/subtype Slava Astashonok Cisco 1 12-09-2003 02:50 PM
ICMP(type:8/subtype:0) miffysmate :-\)\) Computer Support 2 08-27-2003 06:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57