warning: control reaches end of non-void function [-Wreturn-type]

0

in this function is giving me a warning when compiling, to what is it? I read that it is when you declare an int function and it does not return any value, but in this case my function is void, so I do not understand the error.

void *ATERRIZAR(void *datos_avion)
    {
        int i;
        AVION *ptr_datos = (AVION*)datos_avion;
        printf("\nCASA");
        sem_wait(&pistas_aviones);
        i = 0;
        while(pistas[i].num_llegada != 0)
        {
            i = (i+1)%num_pistas;
        }
        pistas[i].num_llegada = ptr_datos->num_llegada;
        pistas[i].num_pasajeros = ptr_datos->num_pasajeros;
        pistas[i].prioridad = ptr_datos->prioridad;
        sleep(1);
        printf("AVION %d ATERRIZA EN PISTA %d\n",ptr_datos->num_llegada , i);
        sleep(1);
        DESOCUPAR_PISTA(i);
        sem_post(&pistas_aviones);
    }
    
asked by EmiliOrtega 13.06.2017 в 09:58
source

1 answer

2

The error message is most enlightening and self-explanatory, let me translate it:

warning: control reaches end of non-void function [-Wreturn-type]

alarma: el control alcanza el final de una función no-void [-Wreturn-type]

In other words, the function does not return void and it ends without returning anything. If you notice the function returns a pointer to void :

  void *ATERRIZAR(void *datos_avion)
//^^^^^^ <----------- puntero a void

But there is not a single statement return in ATERRIZAR .

It marks you as an alarm instead of an error because the function does not return anything despite having said in your statement that it does return it is potentially dangerous. Potentially so that nothing will happen unless you use the value returned by the function ATERRIZAR , which, since it was not assigned within the function, will cause indefinite behavior. You can see more details about that in this question .

In my opinion this should be an error but it marks it as alarm, if you activate the option of the compiler indicated in the alarm itself ( -Wreturn-type ) it will be considered an error instead of an alarm.

    
answered by 13.06.2017 / 10:01
source