In reply to stf.cpll:
According to the 2017 LRM section 11.2.1 Constant expressions
11.2.1 Constant expressions
Some statement constructs require an expression to be a constant expression. The operands of a constant expression consist of constant numbers, strings, parameters, constant bit-selects and part-selects of parameters, constant function calls (see 13.4.3), and constant system function calls only. Constant expressions can use any of the operators defined in Table 11-1.Constant system function calls are calls to certain built-in system functions where the arguments meet conditions outlined in this subclause. When used in constant expressions, these function calls shall be evaluated at elaboration time. The system functions that may be used in constant system function calls are pure functions, i.e., those whose value depends only on their input arguments and that have no side effects."
Based on the above I’d say it is allowed to do such casting as this is not creating any side effect (I could be wrong)
Now what is the output you are expecting after converting the value 7 to a string? maybe what you are looking is for $sformatf(“%0d”, NB)
For example:
module test();
parameter int NB = 7;
parameter string STR = string'(NB);
parameter string STR2 = $sformatf("%0d", NB);
initial begin
$display("NB = %0d", NB);
$display("STR = %s", STR);// ascii code for 7 is "bell"
$display("STR2 = %s", STR2);
end
endmodule
which outputs
# KERNEL: NB = 7
# KERNEL: STR = a
# KERNEL: STR2 = 7
Also look at the https://www.asciitable.com/ so that you can understand what is output you are getting
HTH,