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

234
Visualizações
Can't understand statement (void)(x == y) and 1; in linux typecheck macro

In linux 5.4.21 source code include/linux/irqflags.h,

#define raw_local_save_flags(flags)         \
    do {                        \
        typecheck(unsigned long, flags);    \
        flags = arch_local_save_flags();    \
    } while (0)

and in include/linux/typecheck.h

#define typecheck(type,x) \
({  type __dummy; \
    typeof(x) __dummy2; \
    (void)(&__dummy == &__dummy2); \
    1; \
})

I can't understand how the typecheck macro works. So the typecheck macro makes a variable __dummy having type type, and another variable __dummy2 with the same type with x. It then compares the address of those two variables. I guess putting (void) makes the comparison statement not make error.. but what does this comparison do? How can two variables have same address? and what is the last state 1; ? And what effect does this macro have in the raw_local_save_flags macro? (related to how it is called..) Can somebody explain it to me please? Thanks!

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

0

The comparison &__dummy == &__dummy2 is only permitted if the objects are of the same type, so a compiler will complain if they are not.

See this post about Compound Statements. You can supply a brace-surrounded block (a compound statement) as a valid expression whose value is the last expression in the block.

So in ({ int x = c; x; }) the value of the expression is evaluated as x;

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