473,382 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

declaring a function only if it isn't already declared

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.

Nov 14 '05 #1
2 1466
"no**********@tabi.org" <no**********@tabi.org> writes:
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.


If myfunc() always has the same return type, then you can write a
declaration for it without giving a prototype, e.g.:
int myfunc();
--
"...what folly I commit, I dedicate to you."
--William Shakespeare, _Troilus and Cressida_
Nov 14 '05 #2
<no**********@tabi.org> wrote in message
news:ci********@odak26.prod.google.com...
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!

Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Oliver Corona | last post by:
I am wondering if anyone has any insights on the performance benefit (or detriment) of declaring local variables instead of referencing members. Is allocating memory for a new variable more...
3
by: Fabio | last post by:
Hi all, Whats the real difference between Overloads and Shadows in a Sub???? Thanks in advance, Fabop
3
by: Buddy Robbins | last post by:
Hey folks, I'm trying to use the PathCleanupSpec function from the shell library. The function prototype is: int PathCleanupSpec( LPCWSTR pszDir, LPWSTR pszSpec) In the old days of VB6, I...
5
by: Brett | last post by:
In a class, I have several Private subs. I declare an instance of the class such as: Dim MySelf as new Class1 within a private sub. The motive is to provide access to other subs within the...
4
by: jhightow | last post by:
The following code : For i as system.Int32 = 0 to 4 If i < 2 Then Dim s as System.String s &= i.ToString Console.WriteLine(s) End If Next
11
by: Jim Michaels | last post by:
friend fraction& operator+=(const fraction& rhs); fraction.h(64) Error: error: 'fraction& operator+=(const fraction&)' must take exactly two arguments I practically pulled this out of a C++...
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
1
by: curious2007 | last post by:
Hello everybody, When I try to declare nontemplate friend functions I get the following warning: friend decleration......declares a non-template function (if this is not what you intended,...
1
by: JavaJon | last post by:
Hello, I'm Jon. I've recently picked up Java after using a "gimmick" programming language called GML ( Game Maker Language ). I've read a lot of tutorials and even a Java for Dummies *.pdf book....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.