This came out of a flamewar with Onur (the author of ETP Studio) over how great ETP supposedly is because it has a type-generic concatenation operator: www.tigen.org/kevin.kofler/ti89prog/concat.h.
Usage:
This prints Bonjour Onur123 on the screen.
The string is allocated with alloca, so there is no hardcoded size limit (unlike ETP's crappy string handling which is limited to 50 chars) nor does the buffer have to be freed. (It's valid until the function the macro is used in returns.) And no format string is needed either (that said, an asprintf with a format string would be more efficient than a long series of C(C(C(x,y),z),foo)). (And this also takes variables, not just constants like in the example.
)
For the special case of C(x,"") (i.e. promotion of a single variable to a string), there is S(x).
Note that this works only on those types supported by printf, more explicitly char * (including signed, unsigned, const variants), char, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, float, double, long double. A char is printed using %c (i.e. an actual character), if you don't want that, cast to int. (Yes, __builtin_types_compatible_p is immune to default promotions.)
Enjoy! And no, hypersonic, this is no joke, read the source code to see how it works.
Usage:
#include <tigcclib.h> #include "concat.h" void _main(void) { const char *string1="Onur"; const int integer1=123; DrawStr(10,10,C(C("Bonjour ",string1),integer1),A_NORMAL); ngetchx(); }This prints Bonjour Onur123 on the screen.
The string is allocated with alloca, so there is no hardcoded size limit (unlike ETP's crappy string handling which is limited to 50 chars) nor does the buffer have to be freed. (It's valid until the function the macro is used in returns.) And no format string is needed either (that said, an asprintf with a format string would be more efficient than a long series of C(C(C(x,y),z),foo)). (And this also takes variables, not just constants like in the example.
For the special case of C(x,"") (i.e. promotion of a single variable to a string), there is S(x).
Note that this works only on those types supported by printf, more explicitly char * (including signed, unsigned, const variants), char, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, float, double, long double. A char is printed using %c (i.e. an actual character), if you don't want that, cast to int. (Yes, __builtin_types_compatible_p is immune to default promotions.)
Enjoy! And no, hypersonic, this is no joke, read the source code to see how it works.
