Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to cast function pointer?

Reply
Thread Tools

How to cast function pointer?

 
 
Devrobcom
Guest
Posts: n/a
 
      09-26-2003
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;



 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      09-26-2003
"Devrobcom" <> wrote:

> 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
 
Reply With Quote
 
 
 
 
Derk Gwen
Guest
Posts: n/a
 
      09-26-2003
"Devrobcom" <> wrote:
# 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


--
Derk Gwen http://derkgwen.250free.com/html/index.html
I hope it feels so good to be right. There's nothing more
exhilirating pointing out the shortcomings of others, is there?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Is the result of valid dynamic cast always equal to the result ofcorrespondent static cast? Pavel C++ 7 09-18-2010 11:35 PM
error C2440: 'return' : cannot convert from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Abhijit Bhadra C++ 2 12-01-2004 04:43 PM
malloc - to cast or not to cast, that is the question... EvilRix C Programming 8 02-14-2004 12:08 PM
to cast or not to cast malloc ? MSG C Programming 38 02-10-2004 03:13 PM



Advertisments