Subject: Function pointers and #defines

From: "Justin Carlson" <[email-masked]>
Date: 30 May 2002 12:32:47 -0700

A fair number of places in the headers, we have stuff like this:

void (*_some_fn)(int arg1, int arg2);
#define some_fn(arg1, arg2) _some_fn(arg1, arg2)

Why do we do this, as opposed to:

void (*some_fn)(int arg1, int arg2);

Both syntaxes result in being able to say

some_fn(1, 2);

but the latter is both clearer and shorter.  Is there some deep,
mystical C reason that we use the former, or did someone do it that way
a long time ago and no one has changed it?

-Justin

---

From: "Justin Carlson" <[email-masked]>
Date: 30 May 2002 12:58:44 -0700

On Thu, 2002-05-30 at 12:50, Daniel Jacobowitz wrote:
> At a guess, this prevents taking the address of the function
> unintentionally...

But if you're writing code in such a way that the compiler type checking
doesn't flag this, you deserve what you get.  (IMHO, of course.  :)

-Justin

---

From: Daniel Jacobowitz <[email-masked]>
Date: Thu, 30 May 2002 15:50:52 -0400

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer

---

From: "Kevin D. Kissell" <[email-masked]>
Date: Thu, 30 May 2002 23:18:44 +0200

From: "Daniel Jacobowitz" <[email-masked]>
> At a guess, this prevents taking the address of the function

More likely, some ancient early version of the code was
written with a single global function, some_fn(), and it
was easier to override it with a pointer indirection in
the header than to hunt down and change all invocations.
Sometimes that's good software engineering.  Sometimes
it's just laziness...

            Kevin K.

---

From: "Gleb O. Raiko" <[email-masked]>
Date: Fri, 31 May 2002 13:15:22 +0400

> Sometimes that's good software engineering.  Sometimes

Just remove the declaration, compile, and look at the code generated.
So, #define is just a safety belt.

Regards,
Gleb.