E.g. si necesita asegurarse de que una función tenga un cierto tipo, puede ser útil.
Considera:
// Define how the functions should be defined.
typedef void * jobfunc(void *);
// Use case
void addjob(jobfunc *);
// Ensure they have the right type. Without this, you only get a warning
// for addjob(job2) (see below) - with it, you get an error for the mismatch.
static jobfunc job1;
static jobfunc job2;
// Define one job
static void * job1(void * arg) {
return NULL;
}
// Define another job - accidentally wrong.
static void * job2(int accidentally_wrong) {
return NULL;
}
Creo que usar typedef como una especie de plantilla de función es una práctica bastante oscura, lo más probable es que simplemente confunda al lector. Por ejemplo, me tomó un tiempo interpretar lo que realmente hace tu código. Mi reacción inmediata pero incorrecta al código fue "aha - punteros a la función". – Lundin
@Lundin Tienes razón en cuanto a que es inusual. Pero hace su trabajo. Tal vez el tipo de retorno 'void *' haya agregado confusión; como ejemplo, debería haber tomado un tipo diferente. Sin embargo, no entiendo por qué es tan inusual, es genial para garantizar el tipo correcto y, aparte de la legibilidad y la confusión debido a la desconocida, no veo una desventaja. – glglgl