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

163
Visualizações
mmap return value during error

I could see in the mmap man page the return value during error condition is (void *)-1.

how c compiler will treat (void *) before a constant, here -1.

is the following code snippet is the correct way of checking the error value of mmap?

int *p;
p = (int *)mmap();
if(p == -1)
        printf("error \n");

do we need to use the following error condition check.

if(*p == -1)
        printf("error \n");
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

int *p = NULL;
void *ret = mmap();
if(ret == MAP_FAILED) {  /* Or if(ret == (void *)-1) */
  /* error */
} else {
  p = ret;
}

Check literally with (void *)-1 or use MAP_FAILED macro which is defined to (void *)-1.

if(*p == -1) is incorrect as you can not dereference the pointer unless you ensure the validity of the pointer. Otherwise the behaviour of the program is undefined.

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