Search notes:

Preprocessor: Stringify macros and identifiers

The single hash (#) directive (also known as stringizing operator) creates a quoted string from the value of a preprocessor macro.
#include <stdio.h>

//   QuoteIdent turns an unquoted identifier
//   into a (quoted) string:
//      QuoteIdent(foo) -> "foo"
#define QuoteIdent(ident) #ident

//   QuoteMacro can be used to turn the value
//  (rather than the name/ident)of the macro
//   into a string
#define QuoteMacro(macro) QuoteIdent(macro)


#define FRUIT   strawberry
#define I_LIKE  FRUIT

int main() {
  printf("QuoteIdent(int)    = %s\n", QuoteIdent(int)   );
  printf("QuoteIdent(FRUIT)  = %s\n", QuoteIdent(FRUIT) );
  printf("QuoteMacro(FRUIT)  = %s\n", QuoteMacro(FRUIT) );
  printf("QuoteMacro(I_LIKE) = %s\n", QuoteMacro(I_LIKE));
  printf("QuoteMacro(int)    = %s\n", QuoteMacro(int)   );
}
Github repository about-preprocessor, path: /hash/stringify.c
The program prints:
QuoteIdent(int)    = int
QuoteIdent(FRUIT)  = FRUIT
QuoteMacro(FRUIT)  = strawberry
QuoteMacro(I_LIKE) = strawberry
QuoteMacro(int)    = int

See also

Compare with ## which concatenates two macro values.
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...', 1759405812, '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/stringify(74): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78