String concatenation

In reply to sbellock:

Technically, they are both illegal according to the LRM. A concatenation must be one of

  • All integral expressions, resulting in an integral type
  • All string types or string literals, resulting
  • An unpacked array concatenation in the context of an assignment to an unpacked array.

A string literal is considered either as an integral type or string type depending on its context.

In the first concatenation, num is an integral type and cannot be concatenated with string types. It needs to be cast to a string type first.

In the second concatenation, all its operands are integral types, so the result is integral. But you cannot assign an integral type to a string type without a cast.