B
Ben Pfaff
Old Wolf said:My preference would be:
const char Hex[] = "0123456789ABCDEF";
I'd add "static".
Old Wolf said:My preference would be:
const char Hex[] = "0123456789ABCDEF";
Andrew said:Here's a trick from /C Unleashed/, in a chapter (I believe) Richard
Heathfield wrote:
char *hex = "0123456789ABCDEF";
Actually, what you wrote was:
char Hex[] = "0123456789ABCDEF";
Sorry for misquoting you; I had written that, and then thought,
'Why would I want to modify that?', converted it from an array
to a pointer, and forgot to qualify it with const.
Can you explain how you got from "Why would I want to
modify that?", to converting it to a pointer ?
My preference would be:
const char Hex[] = "0123456789ABCDEF";
Ben said:Old Wolf said:My preference would be:
const char Hex[] = "0123456789ABCDEF";
I'd add "static".
Old Wolf said:Ben said:Old Wolf said:My preference would be:
const char Hex[] = "0123456789ABCDEF";
I'd add "static".
If it's outside of a function then I would agree, to prevent the
compiler making it an external symbol. If it is within the
function then the "static" keyword would seem to not change
the observable behaviour, so I guess you would only add it
if you didn't trust your compiler!
Old said:Ben said:Old Wolf said:My preference would be:
const char Hex[] = "0123456789ABCDEF";
I'd add "static".
If it's outside of a function then I would agree, to prevent the
compiler making it an external symbol. If it is within the
function then the "static" keyword would seem to not change
the observable behaviour, so I guess you would only add it
if you didn't trust your compiler!
CBFalconer said:Old said:Ben said:My preference would be:
const char Hex[] = "0123456789ABCDEF";
I'd add "static".
If it's outside of a function then I would agree, to prevent the
compiler making it an external symbol. If it is within the
function then the "static" keyword would seem to not change
the observable behaviour, so I guess you would only add it
if you didn't trust your compiler!
The 'static' gets it initialized once and for all at compile time,
rather than by executing local code on each entry into the
routine. This reduces run time.
Old said:CBFalconer said:Old said:Ben Pfaff wrote:
My preference would be:
const char Hex[] = "0123456789ABCDEF";
I'd add "static".
If it's outside of a function then I would agree, to prevent the
compiler making it an external symbol. If it is within the
function then the "static" keyword would seem to not change
the observable behaviour, so I guess you would only add it
if you didn't trust your compiler!
The 'static' gets it initialized once and for all at compile time,
rather than by executing local code on each entry into the
routine. This reduces run time.
In theory, possibly. Since there's no difference in observable
behaviour, the compiler is quite entitled to do the same thing
in practice , regardless of whether 'static' is present or not.
In fact I'd wager that most compilers would not reinitialize
the non-static array every time the function is entered.
2006-11-13 said:Old said:CBFalconer said:Old Wolf wrote:
Ben Pfaff wrote:
My preference would be:
const char Hex[] = "0123456789ABCDEF";
I'd add "static".
If it's outside of a function then I would agree, to prevent the
compiler making it an external symbol. If it is within the
function then the "static" keyword would seem to not change
the observable behaviour, so I guess you would only add it
if you didn't trust your compiler!
The 'static' gets it initialized once and for all at compile time,
rather than by executing local code on each entry into the
routine. This reduces run time.
In theory, possibly. Since there's no difference in observable
behaviour, the compiler is quite entitled to do the same thing
in practice , regardless of whether 'static' is present or not.
In fact I'd wager that most compilers would not reinitialize
the non-static array every time the function is entered.
You'ld be wrong. Most compilers implement automatic storage on a
stack, and that content is unknown on function entry. Without
initialization code the operation would be wrong.
CBFalconer said:Old said:CBFalconer said:Old Wolf wrote:
Ben Pfaff wrote:
My preference would be:
const char Hex[] = "0123456789ABCDEF";
I'd add "static".
If it's outside of a function then I would agree, to prevent the
compiler making it an external symbol. If it is within the
function then the "static" keyword would seem to not change
the observable behaviour, so I guess you would only add it
if you didn't trust your compiler!
The 'static' gets it initialized once and for all at compile time,
rather than by executing local code on each entry into the
routine. This reduces run time.
In theory, possibly. Since there's no difference in observable
behaviour, the compiler is quite entitled to do the same thing
in practice , regardless of whether 'static' is present or not.
In fact I'd wager that most compilers would not reinitialize
the non-static array every time the function is entered.
You'ld be wrong. Most compilers implement automatic storage on a
stack, and that content is unknown on function entry. Without
initialization code the operation would be wrong.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.