Skip to content

Instantly share code, notes, and snippets.

@orbitcowboy
Created June 10, 2015 08:22
Show Gist options
  • Save orbitcowboy/2088de476935041057d7 to your computer and use it in GitHub Desktop.
Save orbitcowboy/2088de476935041057d7 to your computer and use it in GitHub Desktop.
How to concatenate two strings in a C macro?
#include <stdio.h>
#define concat0(str1, str2) (str1 " " str2)
#define concat1(str1, str2) (#str1 " " #str2)
int main()
{
printf("%s\n%s\n",
concat0 ("a","b"),
concat1 ("a","b"));
return 0;
}
@math974
Copy link

math974 commented Jun 19, 2022

thank you, it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment