Array initialization magic

I m not 100% sure, but …

Why we can not delare byte array initialization as:

 aVersionCommand: array[0..1] of Byte; := [ 'v', 's' ];

Maybe compiler can cast “char” to “Byte”? And warn if we have overflow (for non-ascii characters)?

It’s not very often when we should have initialized byte array, but it will be cool to use “char” initializers and mix them with some consts (like $123 or maybe even ‘\n’, ‘\r’).

Hello,
you can use the ord method for this:

  aVersionCommand: array[0..1] of Byte; := [ ord('v'),ord( 's') ];

Patrick

@Patrick:

Yes, hardcasting like Byte(‘c’) also works.

But resulting code is cluttered with casting statements!

So, my question was - why no auto-casting? How we should init byte array without this aut-cast?

Hello,

You cannot use quto-casting to char when creating array of Byte because a char doesn’t fit in a byte. They are distinct types.

Best regards.