Search notes:

Preprocessor: Concatenate words to single identifiers

The preprocessor directive ## (two hashes or number signs, aka the token pasting operator) allows to concatenate two symbols into one.
#include <stdio.h>

//  CONCAT(foo, bar) -> foobar
#define CONCAT(id1, id2) id1##id2


int main() {

 // Declare a variable named FooBar, after running the
 // preprocessor, the line will read:
 //
 //    int FooBar
 //
    int CONCAT(Foo, Bar);

    FooBar = 42;

    printf("FooBar = %d\n", FooBar);
}
Github repository about-preprocessor, path: /hash/concatenate.c
The program prints:
FooBar = 42
It doesn't matter if spaces are to the left or right side of the hashes (ident##other is equal to ident ## other):
#include <stdio.h>

#define DECLARE_NUM_A(id1, id2) int id1##id2
#define DECLARE_NUM_B(id1, id2) int id1    ##id2
#define DECLARE_NUM_C(id1, id2) int id1    ##     id2

int main() {

 //
 // The following three lines are expanded by the preprocessor to
 //     int numOne;
 //     int numTwo
 //     int numThree
 //
    DECLARE_NUM_A( num, One   ); 
    DECLARE_NUM_B( num, Two   );
    DECLARE_NUM_C( num, Three );

    numOne   = 42;
    numTwo   = 99;
    numThree = -1;

    printf("The numbers are %d %d %d\n", numOne, numTwo, numThree);

}
Github repository about-preprocessor, path: /hash/concatenate-with-spaces-around-hashes.c

See also

Compare with the single # which creates a quoted string with the value of a macro.
Preprocessor: macros

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759396935, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/C-C-plus-plus/preprocessor/macros/concatenate(98): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78