Questions tagged [stringification]

Stringification refers to the use of the `#` operator in a **C** preprocessor macro to use an argument as a string. Similarly the preprocessor operator `##` can be used to concatenate two arguments, and this tag can also be used.

Stringification refers to the use of the # operator in a C preprocessor macro to use an argument as a string constant. Similarly the preprocessor operator ## can be used to concatenate two arguments, and this tag can also be used.

For full details consult the manual pages:

Related Tags

174 questions
0
votes
3 answers

String concatenation inside macro

To print several fields of a struct, I have to say the following line repeatedly: cout << "field1=" << ptr->get_field1() So I defined the following macro, and use it like this: #define FIELD(s, id) << s"=" << ptr->get_##id() FIELD("field1",…
R71
  • 4,283
  • 7
  • 32
  • 60
0
votes
0 answers

Is it possible to convert a stringified reference from a SCALAR back to a REF?

I would like to write a subroutine (say s2r) which can convert SCALAR input, which is a valid stringified reference, to REF type. As a bonus, I'd like the subroutine to convert the input to the original blessed object (or tied reference), if the…
Moh
  • 304
  • 2
  • 8
0
votes
1 answer

Is it possible to write a C++ function that stringizes?

How would you go if you had to write a proper C++ function that does the same as the operator '#' in macros? It would be useful if it were possible to do it at runtime.
blue
  • 2,683
  • 19
  • 29
0
votes
0 answers

Variable name as a string data member

In C++ is it possible to declare a class which has a private std::string data member which is initialized with the stringized / stringified name of the instance symbol name? I can see that this couldn't work for temporaries, but for lvalues is it…
Luke Peterson
  • 931
  • 1
  • 9
  • 25
-1
votes
1 answer

Accessing and modifying variables using token concatenation in C

I've been reading about stringification and token pasting and I was trying to access a variable using token pasting and modifying it's value. Is such a thing possible? Suppose variables a0 and a1 are defined and at runtime I want to print their…
NISHIT KHARA
  • 63
  • 1
  • 10
-1
votes
2 answers

Can the stringize macro be used here?

Using Pelles C I would like to show or log an unsigned char array. Is it possible to use the stringize macro to show the whole array as hex values instead of iterating through the array with printf(%x)?
user3824211
  • 21
  • 1
  • 6
-1
votes
1 answer

How to fix this stringise error

#define GETSTRING(s) return #s enum a_type { SMALL, MEDIUM, LARGE }; const char* get_data(a_type a) { return GETSTRING(a); } int main() { a_type at = SMALL; const char* s = get_data(at); return 0; } I get compiler…
Angus Comber
  • 9,316
  • 14
  • 59
  • 107
-2
votes
1 answer

Complex one-line conditional checksum definitions

Taking up this code: typedef enum CHECKSUM { DENY = 0, ALLOW = 1 } checksum; #define terminal(x, str) static checksum* terminal_##x; { if(!strcmp(#str, "static")) { static checksum local = ALLOW; terminal_##x = &local; } else { checksum local =…
Genis
  • 1
  • 7
-4
votes
1 answer

How to use a list of strings [which may contain any character] as keys?

Basically I "understand" the ambiguity with using other containers as keys. - do you compare the reference or do you compare the values in it (and how deep). Well can't you just specialize a list and make a custom comparison/hash operator? As I know…
paul23
  • 8,799
  • 12
  • 66
  • 149
1 2 3
11
12