C Macro to build up a string of string pieces and insert (collate) a byte

Viewed 21

I would like to have a C macro to build up a string of pieces of strings plus a byte inserted inmidst, like:

"foo" 0x33 "bar"

so that the resulting string is "foo\0x33bar".

The variable part of the macro should be the 0x33 in this example.

I found a similar question here but it doesn't quite match my problem and furthermore it produces an error in gcc when trying to test it out.

EDIT:

   void func(const char *);
   char s1[] = { 0x90, 0 };
   char s2[] = { 120,0 };
   func(COLLATE(s1,0x33,s2));

   void func(const char *s) {
       for(int i=0;s[i];i++)
          midi.write(s[i]);
   }


such that COLLATE inserts the assembled string there.

EDIT: must correct my example:

func(COLLATE("\0x90",0x33,"\0170"));

Note: The strings may be longer. It's just the point, that one character (0x33) has to be inserted.

0 Answers
Related