Reputation: 726
I want to make a constant string that looks like:
My_Null_String : constant String(1 .. 50) := "NULL***********************";
with all of the *s being Ascii.Nul
characters. It is not possible to do this via the others
keyword, as in:
My_Null_String : constant String(1 .. 50) := "NULL" & (others => Ascii.Nul);
Is there an elegant solution to this that doesn't involve a huge block of Ascii.Nul
characters to fill out the rest of my string?
Thanks
Upvotes: 2
Views: 1207
Reputation: 6430
How about:
My_Null_String : constant String(1 .. 50) := ('N','U','L','L', others => ASCII.Nul);
Upvotes: 1
Reputation: 31699
My_Null_String : constant String(1 .. 50) := "NULL" & (5 .. 50 => ASCII.NUL);
The problem with your original attempt is that in order to evaluate
(others => ASCII.NUL)
the program has to have a way to determine the bounds. It doesn't, and it's not smart enough to make calculations such as figuring out that this is formed by concatenating two strings and therefore we can figure out that the bounds should be whatever is left over after the first string is evaluated. The language would have to make a special case just for this (array concatenation), and it doesn't.
Upvotes: 3