Function pointer

T

teo

I have the functions
static void JogMoveControl(int inputOff,int
inputOn,void(*functionMoveT)(char c),void(*functionMove)(char c));
void t_meno(char comm)
void meno(char comm)

If I call JogMoveControl(1,1,t_meno,meno) no problem

but I have

#define _T_MENO(appo) t_meno(appo)
#define _MENO(appo) meno(appo)

So i should call
JogMoveControl(1,1,_T_MENO,_MENO)
In this case the compiler doesn't found the functions ,_T_MENO e _MENO

Suggestions?

Thanks
Teo
 
S

sathyashrayan

teo said:
I have the functions
static void JogMoveControl(int inputOff,int
inputOn,void(*functionMoveT)(char c),void(*functionMove)(char c));
void t_meno(char comm)
void meno(char comm)

If I call JogMoveControl(1,1,t_meno,meno) no problem

but I have

#define _T_MENO(appo) t_meno(appo)
#define _MENO(appo) meno(appo)

So i should call
JogMoveControl(1,1,_T_MENO,_MENO)
In this case the compiler doesn't found the functions ,_T_MENO e _MENO

Suggestions?
Macros are replaced by the corresponding functions or constants.
But that does not mean that you can use a macros instead of a function
pointers.


--
"combination is the heart of chess"

A.Alekhine

Mail to:
sathyashrayan AT gmail DOT com
 
M

Martin Ambuhl

teo said:
I have the functions
static void JogMoveControl(int inputOff,int
inputOn,void(*functionMoveT)(char c),void(*functionMove)(char c));
void t_meno(char comm)
void meno(char comm)

If I call JogMoveControl(1,1,t_meno,meno) no problem

but I have

#define _T_MENO(appo) t_meno(appo)
#define _MENO(appo) meno(appo)

So i should call
JogMoveControl(1,1,_T_MENO,_MENO)
In this case the compiler doesn't found the functions ,_T_MENO e _MENO

Suggestions?

Suggestion 1: Stop the silliness. Gratuitous #defines are just
masturbation.
Suggestion 2: Learn that function-like macros need to have the () to be

expanded as you expect.
with
#define T_MENO(x) t_meno(x)
the line
T_MENO;
is expanded to [no shock here]
T_MENO;
while
T_MENO();
is expanded to
t_meno();
Suggestion 3: Stop using identifiers starting with an underscore
followed by a capital letter. Hell, stop using identifiers
starting with an underscore, period. You won't remember
when they're OK and when they're not, anyway.


T_MENO()
 
R

Richard Bos

teo said:
static void JogMoveControl(int inputOff,int
inputOn,void(*functionMoveT)(char c),void(*functionMove)(char c));
void t_meno(char comm)
void meno(char comm)

If I call JogMoveControl(1,1,t_meno,meno) no problem

but I have

#define _T_MENO(appo) t_meno(appo)
#define _MENO(appo) meno(appo)

So i should call
JogMoveControl(1,1,_T_MENO,_MENO)
In this case the compiler doesn't found the functions ,_T_MENO e _MENO

No surprise. _T_MENO(arg) is not the same macro as _T_MENO. If you want
to use just the name, you need a macro which #defined just that name.

(And btw, identifiers starting with _ and a capital letter aren't yours
to use - they're reserved for the implementation.)

Richard
 
L

Lawrence Kirby

I have the functions
static void JogMoveControl(int inputOff,int
inputOn,void(*functionMoveT)(char c),void(*functionMove)(char c));
void t_meno(char comm)
void meno(char comm)

If I call JogMoveControl(1,1,t_meno,meno) no problem

but I have

#define _T_MENO(appo) t_meno(appo)
#define _MENO(appo) meno(appo)

You have deined function-like macros above. These are only expanded when
the macro name is followed by (...) . If you want a general replacement
you need to define them as object-like macros:

#define _T_MENO t_meno
#define _MENO meno

But not that as others have said avoid identifiers starting with an
underscore, especially ones starting with an underscore followed by
another underscore or uppercase letter. Those are reserved for use by the
implementation, they should never be defined in user code.

Lawrence
 
P

pete

teo said:
I have the functions
static void JogMoveControl(int inputOff,int
inputOn,void(*functionMoveT)(char c),void(*functionMove)(char c));
void t_meno(char comm)
void meno(char comm)

If I call JogMoveControl(1,1,t_meno,meno) no problem

but I have

#define _T_MENO(appo) t_meno(appo)
#define _MENO(appo) meno(appo)

So i should call
JogMoveControl(1,1,_T_MENO,_MENO)
In this case the compiler doesn't found the functions ,_T_MENO e _MENO

Suggestions?

What you're trying to accomplish isn't even right.

JogMoveControl(1, 1, t_meno(appo), meno(appo))

is not going to be a valid function call with that
JogMoveControl prototype
and is never going to be a valid function call
as long as the meno functions return type void.
 
J

john_bode

teo said:
I have the functions
static void JogMoveControl(int inputOff,int
inputOn,void(*functionMoveT)(char c),void(*functionMove)(char c));
void t_meno(char comm)
void meno(char comm)

If I call JogMoveControl(1,1,t_meno,meno) no problem

but I have

#define _T_MENO(appo) t_meno(appo)
#define _MENO(appo) meno(appo)

So i should call
JogMoveControl(1,1,_T_MENO,_MENO)
In this case the compiler doesn't found the functions ,_T_MENO e _MENO

Suggestions?

Thanks
Teo

First suggestion: ditch the macros entirely. As written, they add
nothing to the code. What purpose are they supposed to serve?

Second suggestion: if you have a good reason for using the macros
(maybe because you expect the function names to change at some point),
don't use function-like macros; just create a simple macro for the
function name:

#define T_MENO t_meno
#define MENO meno

That way, both T_MENO(foo) and T_MENO will expand correctly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top