<> wrote in message
news:cifku3$...
> I'm writing a Linux device driver that needs to compile with several
> different Linux versions. In my code, I need to reference certain
> functions by their address alone. Something like this:
>
> int myfunc(char *x);
> if (memory_test[x] == myfunc)
> ...
>
> In other words, I don't care about the return values or the parameters
> of myfunc(), I just need to reference it.
>
> In my case, myfunc() isn't a function that I've defined, but it may be
> declared in a header file that I'm including. The problem is that each
> Linux version has different header files for myfunc(), so that I can't
> really know which header file I need to include in order to get
> myfunc() declared. Not only that, but the function declaration for
> myfunc() isn't exactly the same, either.
>
> Therefore, I was hoping for something like this:
>
> #if !defined(myfunc)
> void myfunc(void);
> #endif
>
> This doesn't work, of course, because myfunc() is not a macro, so
> defined() doesn't work on it. All I want to do is create a prototype
> for myfunc() that is guaranteed not to cause any function redefinition
> errors.
I just use header file for each function. Each
header file has something like:
// This is file name MyFunc.h
#if !defined(MY_FUNC)
#define MY_FUNC
extern int MyFunc(char * whatzit);
#endif //!defined(MY_FUNC)
I use #include to include the function's header
file in each compilation unit that wants to
refer to the function (either wanting to call
the function or just get the function's address).
The "MY_FUNC" preprocessor symbol is simply the
uppercase representation of the function name,
and the header file name is simply the function
name followed by ".h".
--
----------------------------
Jeffrey D. Smith
Farsight Systems Corporation
24 BURLINGTON DRIVE
LONGMONT, CO 80501-6906
http://www.farsight-systems.com
z/Debug debugs your Systems/C programs running on IBM z/OS for FREE!