How to cast function pointer?

D

Devrobcom

Hi
I know that this is not the Lint forum, but I get some Lint warnings
when setting my pointers to NULL. And the problem is
I don't know howto cast a function ptr the right way.

typedef int FP(char*, char*);

FP *pfp;
pfp = NULL; --error 64: (Error -- Type mismatch (assignment) (ptrs to
void/nonvoid))

I have tried, without success:
pft = (FP*)NULL;
pfp = (int(*)(char*, char*))NULL;
 
R

Richard Bos

Devrobcom said:
I know that this is not the Lint forum, but I get some Lint warnings
when setting my pointers to NULL. And the problem is
I don't know howto cast a function ptr the right way.

typedef int FP(char*, char*);

FP *pfp;
pfp = NULL; --error 64: (Error -- Type mismatch (assignment) (ptrs to
void/nonvoid))

That is an incorrect error. NULL is required to be a null pointer
constant; therefore, when being assigned to _any_ type of pointer, it is
required to result in a null pointer of the appropriate type; and null
pointers can, without problem, be assigned to any kind of pointer, no
matter whether they're object or function pointers. Lint is talking out
of its hat. There is no more correct way to do this - what you've done
is already quite correct.

Richard
 
D

Derk Gwen

# Hi
# I know that this is not the Lint forum, but I get some Lint warnings
# when setting my pointers to NULL. And the problem is
# I don't know howto cast a function ptr the right way.
#
# typedef int FP(char*, char*);
#
# FP *pfp;
# pfp = NULL; --error 64: (Error -- Type mismatch (assignment) (ptrs to
# void/nonvoid))
#
# I have tried, without success:
# pft = (FP*)NULL;
# pfp = (int(*)(char*, char*))NULL;

I don't use NULL, I just use 0.

cat <<':eof' >/tmp/t.c
void f(void) {
typedef int FP(char*, char*);
FP *pfp;
pfp = 0;
}
:eof
cc -c /tmp/t.c
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top