473,802 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to cast function pointer?

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;

Nov 13 '05 #1
2 11527
"Devrobcom" <De*******@hotm ail.com> 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
Nov 13 '05 #2
"Devrobcom" <De*******@hotm ail.com> 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?
Nov 13 '05 #3

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

Similar topics

18
5956
by: Graham Nicholls | last post by:
Hi. I'm having some fun with numbers. I've extraced an image sizes from a jpeg file img_x,img_y=image.getsize() then I'm trying to use those sizes to scale the image, but because python has decided that they are integers, I keep getting division by zero errors
5
2021
by: Patrick Guio | last post by:
Dear all, I have a C function that returns a void pointer (void *). This object pointer is actually a pointer to function. I have the following declarations: void *pobj; double (*func)(double);
10
2621
by: LaEisem | last post by:
On-the-job, I have "inherited" a lot of old C language software. A question or two about when "casting" of null pointer constants is needed has occurred during behind-the-scenes cleanup of some of that software. That subject seems not to be addressed, at least not directly, in the C FAQ where FAQ 5.2 seems most relevant. References: * C FAQ 5.2 Null pointers (Including conditions where "casting" of null pointer...
9
2729
by: Frederick Gotham | last post by:
Let's assume that we're working on the following system: CHAR_BIT == 8 sizeof( char* ) == 4 (i.e. 32-Bit) Furthermore, lets assume that the memory addresses are distributed as follows: 0x00000000 through 0xFFFFFFFE : Valid byte addresses
7
5292
by: llothar | last post by:
When i use -W4 on visual c 7.0 i get warning C4054 translator1.c(1703) : warning C4054: 'type cast' : from function pointer 'void * (__cdecl *)(se_agent *)' to data pointer 'void *' translator1.c(1703) : warning C4152: nonstandard extension, function/ data pointer conversion in expression whenever i cast a function pointer to a void* or back. Is there any reason for this warning ? Looks like good C code for me.
18
2217
by: Felix Kater | last post by:
I haven't been thinking about it for years but recently I've stumbled on the fact that 'casting' is actually doing (at least) two different things: On the one hand 'casting' means: 'Change something into somthing else'. Example: double d=9.99; long l=(double)d; On the other hand 'casting' means: 'Treating something as something else without change'. For instance when casting function pointers.
1
452
by: etienne | last post by:
Hello all, i'm experimenting a problem in trying to cast a char * variable to a pointer to a function. My problem is that I want to execute functions in threads, using the pthread_create function. The name of the functions are read in txt file at runtime. So I want to do something like char * func_to_run = scanf(the, good, args); pthread_create (thread, attr, (magic cast)funct_to_run, arg);
5
10822
by: =?utf-8?b?QXNiasO4cm4gU8OmYsO4?= | last post by:
For various reasons, I have a number of typedefs to name arrays of various sizes and for various purposes. I also have functions taking variables of such typedef-ed types as their input arguments. Now I want to feed one such function part of a larger array. To have the correct type in the call to the function, I am trying to use a cast. But I can not find a cast that does not produce warnings. See the line with the comment "Gives...
3
2090
by: Bartc | last post by:
I have a variable like this: int *p; Sometimes this points to an int location containing the address of a void(void) function. How can I cast it so that I can call that function? I've tried casting to void **(void). The compiler keeps saying such a cast
7
3953
by: * Tong * | last post by:
Hi, I couldn't figure out how to properly type cast in this case: $ cat -n type_cast.c 1 #include <stdio.h> 2 3 typedef unsigned char Byte; 4 typedef signed char Small_Int; 5
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10536
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.