Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't the token pasting operator (##) be used to concatenate two strings?

Why can't the token pasting operator be used to concatenate two strings? For example;

#include <stdio.h>
#define  MESSAGE "hello"##"world" 

int main() {
printf(MESSAGE);
}

error: pasting ""hello"" and ""world"" does not give a valid preprocessing token

like image 683
İlker Deveci Avatar asked Oct 24 '25 02:10

İlker Deveci


1 Answers

Pasting 2 string literals is invalid because it does not form a valid single token. Note however that there is no need to use ## in this case as merely juxtaposing two (or more) string literals is legal and parsed as a single string.

like image 102
chqrlie Avatar answered Oct 25 '25 16:10

chqrlie