Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

If BAD_EOF was a macro, you could stringize it:

#define STRINGIZE_DETAIL_(v) #v #define STRINGIZE(v) STRINGIZE_DETAIL_(v) "My error code is #" STRINGIZE(BAD_EOF) "!" 

But it's not (and that's just about always a good thing), so you need to formatformat the string:

stringf("My error code is #%d!", BAD_EOF) stringstream ss; ss << "My error code is #" << BAD_EOF << "!"; ss.str() 

If this was a huge concern for you (it shouldn't be, definitely not at first), use a separate, specialized string for each constant:

unsigned const BAD_EOF = 1; #define BAD_EOF_STR "1" 

This has all the drawbacks of a macro plus more to screwup maintain for a tiny bit of performance that likely won't matter for most apps. However, if you decide on this trade-off, it has to be a macro because the preprocessor can't access values, even if they're const.

If BAD_EOF was a macro, you could stringize it:

#define STRINGIZE_DETAIL_(v) #v #define STRINGIZE(v) STRINGIZE_DETAIL_(v) "My error code is #" STRINGIZE(BAD_EOF) "!" 

But it's not (and that's just about always a good thing), so you need to format the string:

stringf("My error code is #%d!", BAD_EOF) stringstream ss; ss << "My error code is #" << BAD_EOF << "!"; ss.str() 

If this was a huge concern for you (it shouldn't be, definitely not at first), use a separate, specialized string for each constant:

unsigned const BAD_EOF = 1; #define BAD_EOF_STR "1" 

This has all the drawbacks of a macro plus more to screwup maintain for a tiny bit of performance that likely won't matter for most apps. However, if you decide on this trade-off, it has to be a macro because the preprocessor can't access values, even if they're const.

If BAD_EOF was a macro, you could stringize it:

#define STRINGIZE_DETAIL_(v) #v #define STRINGIZE(v) STRINGIZE_DETAIL_(v) "My error code is #" STRINGIZE(BAD_EOF) "!" 

But it's not (and that's just about always a good thing), so you need to format the string:

stringf("My error code is #%d!", BAD_EOF) stringstream ss; ss << "My error code is #" << BAD_EOF << "!"; ss.str() 

If this was a huge concern for you (it shouldn't be, definitely not at first), use a separate, specialized string for each constant:

unsigned const BAD_EOF = 1; #define BAD_EOF_STR "1" 

This has all the drawbacks of a macro plus more to screwup maintain for a tiny bit of performance that likely won't matter for most apps. However, if you decide on this trade-off, it has to be a macro because the preprocessor can't access values, even if they're const.

replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

If BAD_EOF was a macro, you could stringize it:

#define STRINGIZE_DETAIL_(v) #v #define STRINGIZE(v) STRINGIZE_DETAIL_(v) "My error code is #" STRINGIZE(BAD_EOF) "!" 

But it's not (and that's just about always a good thing), so you need to format the string:

stringf("My error code is #%d!", BAD_EOF) stringstream ss; ss << "My error code is #" << BAD_EOF << "!"; ss.str() 

If this was a huge concern for you (it shouldn't be, definitely not at first), use a separate, specialized string for each constant:

unsigned const BAD_EOF = 1; #define BAD_EOF_STR "1" 

This has all the drawbacks of a macro plus more to screwup maintain for a tiny bit of performance that likely won't matterwon't matter for most apps. However, if you decide on this trade-off, it has to be a macro because the preprocessor can't access values, even if they're const.

If BAD_EOF was a macro, you could stringize it:

#define STRINGIZE_DETAIL_(v) #v #define STRINGIZE(v) STRINGIZE_DETAIL_(v) "My error code is #" STRINGIZE(BAD_EOF) "!" 

But it's not (and that's just about always a good thing), so you need to format the string:

stringf("My error code is #%d!", BAD_EOF) stringstream ss; ss << "My error code is #" << BAD_EOF << "!"; ss.str() 

If this was a huge concern for you (it shouldn't be, definitely not at first), use a separate, specialized string for each constant:

unsigned const BAD_EOF = 1; #define BAD_EOF_STR "1" 

This has all the drawbacks of a macro plus more to screwup maintain for a tiny bit of performance that likely won't matter for most apps. However, if you decide on this trade-off, it has to be a macro because the preprocessor can't access values, even if they're const.

If BAD_EOF was a macro, you could stringize it:

#define STRINGIZE_DETAIL_(v) #v #define STRINGIZE(v) STRINGIZE_DETAIL_(v) "My error code is #" STRINGIZE(BAD_EOF) "!" 

But it's not (and that's just about always a good thing), so you need to format the string:

stringf("My error code is #%d!", BAD_EOF) stringstream ss; ss << "My error code is #" << BAD_EOF << "!"; ss.str() 

If this was a huge concern for you (it shouldn't be, definitely not at first), use a separate, specialized string for each constant:

unsigned const BAD_EOF = 1; #define BAD_EOF_STR "1" 

This has all the drawbacks of a macro plus more to screwup maintain for a tiny bit of performance that likely won't matter for most apps. However, if you decide on this trade-off, it has to be a macro because the preprocessor can't access values, even if they're const.

added 135 characters in body
Source Link
Roger Pate
Roger Pate

If BAD_EOF was a macro, you could stringize it:

#define STRINGIZE_DETAIL_(v) #v #define STRINGIZE(v) STRINGIZE_DETAIL_(v) "My error code is #" STRINGIZE(BAD_EOF) "!" 

But it's not (and that's just about always a good thing), so you need to format the string:

stringf("My error code is #%d!", BAD_EOF) stringstream ss; ss << "My error code is #" << BAD_EOF << "!"; ss.str() 

If this was a huge concern for you (it shouldn't be, definitely not at first), use a separate, specialized string for each constant:

unsigned const BAD_EOF = 1; #define BAD_EOF_STR "1" 

This has all the drawbacks of a macro plus more to screwup maintain for a tiny bit of performance that likely won't matter for most apps. However, if you decide on this trade-off, it has to be a macro because the preprocessor can't access values, even if they're const.

If BAD_EOF was a macro, you could stringize it:

#define STRINGIZE_DETAIL_(v) #v #define STRINGIZE(v) STRINGIZE_DETAIL_(v) "My error code is #" STRINGIZE(BAD_EOF) "!" 

But it's not (and that's just about always a good thing), so you need to format the string:

stringf("My error code is #%d!", BAD_EOF) stringstream ss; ss << "My error code is #" << BAD_EOF << "!"; ss.str() 

If this was a huge concern for you (it shouldn't be, definitely not at first), use a separate, specialized string for each constant:

unsigned const BAD_EOF = 1; #define BAD_EOF_STR "1" 

This has all the drawbacks of a macro plus more to screwup maintain for a tiny bit of performance that likely won't matter for most apps.

If BAD_EOF was a macro, you could stringize it:

#define STRINGIZE_DETAIL_(v) #v #define STRINGIZE(v) STRINGIZE_DETAIL_(v) "My error code is #" STRINGIZE(BAD_EOF) "!" 

But it's not (and that's just about always a good thing), so you need to format the string:

stringf("My error code is #%d!", BAD_EOF) stringstream ss; ss << "My error code is #" << BAD_EOF << "!"; ss.str() 

If this was a huge concern for you (it shouldn't be, definitely not at first), use a separate, specialized string for each constant:

unsigned const BAD_EOF = 1; #define BAD_EOF_STR "1" 

This has all the drawbacks of a macro plus more to screwup maintain for a tiny bit of performance that likely won't matter for most apps. However, if you decide on this trade-off, it has to be a macro because the preprocessor can't access values, even if they're const.

added 453 characters in body; added 135 characters in body; added 1 characters in body; deleted 135 characters in body; deleted 53 characters in body
Source Link
Roger Pate
Roger Pate
Loading
added 116 characters in body
Source Link
Roger Pate
Roger Pate
Loading
Source Link
Roger Pate
Roger Pate
Loading