D
Dennis Chang
Hi all,
I was reading about function pointers and came across something which
intrigued me.
K&R2 calls qsort (pg.119) within main as so:
qsort( (void **) lineptr, 0, nlines-1, (int (*) (void *, void*))(numeric ?
numcmp : strcmp) );
I guess what interests me is the nameless function pointer and then the
binding of a name to it.
I've worked with nameless functions before in other languages but not in C.
So is my reading of this qsort function call correct?
Another question presents itself to me on the following page of K&R2
(pg.120).
/* Declaration qsort */
void qsort( ... )
{
void swap (void *, int, int);
/* ... */
}
It's true you can't declare a function within a function? So that the
forward declaration of swap within qsort doesn't prevent swap from being
called from other functions (since it's defined elsewhere)? So what's the
point of a forward declaration within a function declaration?
Lastly, it is possible to declare a nameless function within a function?
I.e.,
int max20(int a)
{
return { a > 20 ? a : 20 };
}
I mean the {} declares a nameless function, no?
Thanks,
Dennis.
I was reading about function pointers and came across something which
intrigued me.
K&R2 calls qsort (pg.119) within main as so:
qsort( (void **) lineptr, 0, nlines-1, (int (*) (void *, void*))(numeric ?
numcmp : strcmp) );
I guess what interests me is the nameless function pointer and then the
binding of a name to it.
I've worked with nameless functions before in other languages but not in C.
So is my reading of this qsort function call correct?
Another question presents itself to me on the following page of K&R2
(pg.120).
/* Declaration qsort */
void qsort( ... )
{
void swap (void *, int, int);
/* ... */
}
It's true you can't declare a function within a function? So that the
forward declaration of swap within qsort doesn't prevent swap from being
called from other functions (since it's defined elsewhere)? So what's the
point of a forward declaration within a function declaration?
Lastly, it is possible to declare a nameless function within a function?
I.e.,
int max20(int a)
{
return { a > 20 ? a : 20 };
}
I mean the {} declares a nameless function, no?
Thanks,
Dennis.