tapio / rlutil

C and C++ utilities for cross-platform console roguelike game creation.
http://tapio.github.com/rlutil/
229 stars 42 forks source link

Use #defined color constants instead of strings #44

Closed cxong closed 8 years ago

cxong commented 8 years ago

The problem is that using const char*/const std::string in the header means that if two modules both using rlutil are linked, there will be duplicate symbols, resulting in a link error.

The solution used here is to use #defines. This is C so it's an acceptable practice. Another solution would be to use static const char */static const std::string. There are pros and cons to both; with the former you can do printf(ANSI_GREEN "hello " ANSI_RED "world!");; with the latter you can take its address and is a bit more memory efficient.

See http://stackoverflow.com/q/1431576/2038264

nabijaczleweli commented 8 years ago

Move to top (if not done already, mobile sucks) and prefix all macros with RLUTIL_

cxong commented 8 years ago

On second thought, it's better to use static strings because preprocessor ignores namespaces, which might break anyone using something like rlutil::ANSI_RED. See #45 instead