linux-mips
[Top] [All Lists]

Re: Function pointers and #defines

To: "Daniel Jacobowitz" <dan@debian.org>, "Justin Carlson" <justinca@cs.cmu.edu>
Subject: Re: Function pointers and #defines
From: "Kevin D. Kissell" <kevink@mips.com>
Date: Thu, 30 May 2002 23:18:44 +0200
Cc: <linux-mips@oss.sgi.com>
References: <1022787167.14210.472.camel@ldt-sj3-022.sj.broadcom.com> <20020530195052.GA10587@branoic.them.org>
Sender: owner-linux-mips@oss.sgi.com
From: "Daniel Jacobowitz" <dan@debian.org>
> On Thu, May 30, 2002 at 12:32:47PM -0700, Justin Carlson wrote:
> > 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?
> 
> At a guess, this prevents taking the address of the function
> unintentionally...

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.


<Prev in Thread] Current Thread [Next in Thread>