Global Strings
This is a silly question for someone coding this long but... How do I create a global string ? The following emaple doesn''t work but I''d imagine it something along these lines
const byte *TOKEN_QUIT = "quit";
Normaly I''d create the ram then fill it but essentially I just want a replacement for #define that has a type...
I don't see anything wrong with what you have there, but it's not exactly how I'd do it. At the global scope (not in any function) I'd do:
Then you can just use "szTokenQuit" anyplace in your code to get to the string.
The real advantage to this is that there is only one instance of the string "quit" in memory. If you use a #define, then you could have instances of your string for each usage of the macro (compiler optimizations asside).
The disadvantage is that if you are using multiple source files then you have to declare the variable in one file and then "extern" it from every other file that want's to use it.
Edited by - syzygy on July 23, 2000 9:25:53 PM
const char szTokenQuit[] = "quit";
Then you can just use "szTokenQuit" anyplace in your code to get to the string.
The real advantage to this is that there is only one instance of the string "quit" in memory. If you use a #define, then you could have instances of your string for each usage of the macro (compiler optimizations asside).
The disadvantage is that if you are using multiple source files then you have to declare the variable in one file and then "extern" it from every other file that want's to use it.
Edited by - syzygy on July 23, 2000 9:25:53 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement