Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
Use name of #define parameter without stringification

Is there a way to get the exact words passed into the #define without stringifying? Example use case:

#define NUM 1

#define CREATE_FUN(X) \
void prefix_X() { \ // used exact words passed in
    int x = X; \ // use value later on
}

CREATE_FUN(NUM)

And output would look like:

void prefix_NUM() {
    int x = 1;
}
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Use the token concatenation (##):

#define NUM 1

#define CREATE_FUN(X) \
void prefix_##X() { \
    int x = X; \
}

CREATE_FUN(NUM)
over 4 years ago · Santiago Trujillo Relatório

0

#define CREATE_FUN(X) \
int prefix_##X() { \
    int x = X; \
    return x; \
}

CREATE_FUN(NUM)
over 4 years ago · Santiago Trujillo Relatório

0

You can use Token Pasting(##) operator:

#define CREATE_FUN(X) int prefix_##X() { int x=X; return x;}

Sample use case:

Some compilers provide an extension that allows ## to appear after a comma and before __VA_ARGS__, in which case

  1. the ## does nothing when VA_ARGS is non-empty

  2. removes the comma when VA_ARGS is empty.

This makes it possible to define macros with variable number of arguments such as fprintf (stderr, format, ##__VA_ARGS__)

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda