Re: [PATCH 22/82] remove linux/version.h from drivers/message/fus ion

Nathan Lynch
2005-07-20T17:54:09Z

Matt Domsch wrote:
> On Tue, Jul 19, 2005 at 06:07:41PM -0600, Moore, Eric Dean wrote:
> > On Tuesday, July 12, 2005 8:17 PM, Matt Domsch wrote:
> > > In general, this construct:
> > >
> > > > > -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,6))
> > > > > -static int inline scsi_device_online(struct scsi_device *sdev)
> > > > > -{
> > > > > - return sdev->online;
> > > > > -}
> > > > > -#endif
> > >
> > > is better tested as:
> > >
> > > #ifndef scsi_device_inline
> > > static int inline scsi_device_online(struct scsi_device *sdev)
> > > {
> > > return sdev->online;
> > > }
> > > #endif
> > >
> > > when you can. It cleanly eliminates the version test, and tests for
> > > exactly what you're looking for - is this function defined.
> > >
> >
> > What you illustrated above is not going to work.
> > If your doing #ifndef around a function, such as scsi_device_online, it's
> > not going to compile
> > when scsi_device_online is already implemented in the kernel tree.
> > The routine scsi_device_online is a function, not a define. For a define
> > this would work.
>
> Sure it does, function names are defined symbols.
>

$ cat foo.c
static int foo(void) { return 0; }
#ifndef foo
static int foo(void) { return 0; }
#endif

$ gcc -c foo.c
foo.c:3: error: redefinition of 'foo'
foo.c:1: error: previous definition of 'foo' was here

I believe #ifdef/#ifndef can test only preprocessor symbols.

Nathan