\$\begingroup\$
\$\endgroup\$
1
In VHDL one can cast one type to another using the name of the other type e.g
signal x : std_logic_vector(7 downto 0);
signal y : signed(7 downto 0);
...
y <= signed(x)
Here we use the type as if it was name of a function. Where exactly are these "cast functions" defined and why are they confused with the type name?
asked Aug 13, 2022 at 21:52
-
1\$\begingroup\$ It's not a cast it's a type conversion , e.g. EEE Std 1076-2008 9.3.6 Type conversions "type_conversion ::= type_mark (expression ) ", an inherent basic operation (5. Types 5.1 General). There are rules (9.3.6) requiring types be closely related. Array types signed and std_logic_vector are closely related both having the same dimensionality and same element base type. Unrelated types would require conversion functions (e.g. to_signed found in IEEE package numeric_std). \$\endgroup\$user16145658– user161456582022年08月13日 22:53:16 +00:00Commented Aug 13, 2022 at 22:53
1 Answer 1
\$\begingroup\$
\$\endgroup\$
2
"Signed
" and "unsigned
" are declared as "SUBTYPE
" of "std_logic_vector
", there is no need to declare cast functions.
It's a bit like in C when writing "(signed long)var
"
answered Aug 13, 2022 at 22:01
-
1\$\begingroup\$ I see, so this is the difference between cast and conversion function. \$\endgroup\$quantum231– quantum2312022年08月13日 23:06:54 +00:00Commented Aug 13, 2022 at 23:06
-
2\$\begingroup\$ Prior to -2008 signed and unsigned are types. In -2008 and -2019 they are resolved subtypes of types unresolved_signed and unresolved_unsigned not std_logic_vector. \$\endgroup\$user16145658– user161456582022年08月14日 01:16:27 +00:00Commented Aug 14, 2022 at 1:16
lang-vhdl