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

300
Visualizações
"#define something something" in C

I'm looking at some microcontroller C headers and there is code like this:

#define OSCCONL OSCCONL
extern volatile uint8_t OSCCONL __attribute__((__sfr__));
#define OSCCONH OSCCONH
extern volatile uint8_t OSCCONH __attribute__((__sfr__));
#define CLKDIV CLKDIV
extern volatile uint16_t CLKDIV __attribute__((__sfr__));
__extension__ typedef struct tagCLKDIVBITS {...}

What is the purpose of those repetitive "#define A A" ?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

As the preprocessor does not know anything about the C language and variables you need to add some definitions know if the variable (variable) will be defined in the C code. You can use those definitions later in the code.

Example:

#if defined(OSCONL)
OSCONL = something;
#endif

And if your microcontroller does not have this register this part of the code will not be compiled. It is a very common technique.

EDIT:

But wouldn't that work the same if it just had #define OSCCONL

The idea is to have the same #define as variable or function name. It makes code consistent and easy to remember.

Otherwise, you would have to have different #define and object name making coding more difficult, as our would have to remember both. In this convention, you can read the documentation of the uC and use the same name to check if this object exists without remembering how the #define is called.

over 4 years ago · Santiago Trujillo Relatório

0

One purpose could be that it can be used in a macro check such as #ifdef or #ifndef

This allows for conditional compiling where only parts of the source code will be compiled into the binary.

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