defines both a type and a subtype

Discussion in 'VHDL' started by valtih1978, Nov 13, 2012.

  1. valtih1978

    valtih1978 Guest

    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?
    valtih1978, Nov 13, 2012
    #1
    1. Advertising

  2. valtih1978

    Andy Guest

    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
    Andy, Nov 13, 2012
    #2
    1. Advertising

  3. valtih1978

    valtih1978 Guest

    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
    >
    valtih1978, Nov 14, 2012
    #3
  4. valtih1978

    Andy Guest

    Oh, I forgot who you were. I refuse to argue with you.

    Andy
    Andy, Nov 14, 2012
    #4
  5. valtih1978

    valtih1978 Guest

    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
    valtih1978, Nov 15, 2012
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hari

    subtype for integers

    Hari, Jan 7, 2004, in forum: VHDL
    Replies:
    5
    Views:
    620
    Jim Lewis
    Jan 12, 2004
  2. theotyflos
    Replies:
    3
    Views:
    466
    Thomas Matthews
    Feb 19, 2004
  3. Replies:
    3
    Views:
    7,831
  4. tonyfai

    Subtype of User-Defined Type?

    tonyfai, Dec 6, 2007, in forum: VHDL
    Replies:
    0
    Views:
    457
    tonyfai
    Dec 6, 2007
  5. Ryan Liu
    Replies:
    1
    Views:
    757
    Mr. Arnold
    Aug 1, 2010
Loading...

Share This Page