Archived

This topic is now archived and is closed to further replies.

gimp

Global Strings

Recommended Posts

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...

Share this post


Link to post
Share on other sites
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:

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

Share this post


Link to post
Share on other sites