I would like to define a string (char array) of ASCII blanks exactly as long as some static const int or macro. I want it to happen at compile time, not run time.
For example, if
static const int numBlanks = 5
then
char foo[] = " "
(five blanks)
and if
numBlanks = 3
then
char foo[] = " "
(three blanks)
and so forth. (Why? I want to use it with strstr()
to locate a sequence of at least numBlanks
, with numBlanks
setable at compile time.)
Yes, you do it with new
, memset()
and a /0
, but I want to do it once at compile time, not again and again at run time.
Yes, I could come pretty close with
char foo[] = " ";
foo[numBlanks] = '\0';
and a comment or assert()
to make sure numBlanks
was never greater than the compiled length of foo
.
But can I do this all at compile time? Define a char array of all blanks exactly numBlanks long, where numBlanks
is a C++ static const int or a macro?