473,412 Members | 2,096 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,412 software developers and data experts.

error C2440: 'initializing' : cannot convert from 'void *' to 'void (__cdecl *)(void)

Hi !!
I'm trying to convert C code to C++.

This is my function:


static void (*selection)(void) = NULL;
static void (*pick)(GLint name) = NULL;

void zprSelectionFunc(void (*f)(void))
{
selection = f;
}

void zprPickFunc(void (*f)(GLint name))
{
pick = f;
}


But I have this problem when I compile:

error C2440: 'initializing' : cannot convert from 'void *' to 'void (__cdecl *)(void)
Conversion from 'void*' to pointer to non-'void' requires an explicit cast


Please!!...help me whit this problem...Thanks.
Oct 1 '08 #1
2 13149
weaknessforcats
9,208 Expert Mod 8TB
Your problem is not in this code which I compiled without error using Visual Studio.NET 2008.
Oct 1 '08 #2
donbock
2,426 Expert 2GB
(It would have helped if you had identified which line of your program was identified in the error message.)

NULL is a data pointer. It essentially [or actually, I don't quite remember which] has type void*.

'select' and 'pick' are function pointers. Pedantically speaking, data pointers and function pointers are not interchangeable. The C Standard allows for the possibility that a processor might use different size registers for data and function pointers.

As it turns out, most processors and compiler implementations will happily interconvert data and function pointers. That is probably true for your compiler too. Perhaps you have the most pedantic level of error checking enabled. Or perhaps C++ is naturally pedantic about this.

The most portable way to initialize your function pointers is to set them equal to literal zero. My long-standing practice has been to do the following:
Expand|Select|Wrap|Line Numbers
  1. #define FNULL 0L
  2. void (*select)(void) = FNULL;
This is my practice for C code. There may be a preferred idiom in C++.
Oct 2 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Abhijit Bhadra | last post by:
Hi , I was trying to build my project in VC with latest Service Packs but got this error . C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(125) : error C2440: 'return' :...
3
by: Peter | last post by:
Hi, I am trying to compile an existing project (originally c) in .NET (rename .c files to .cpp). After fixing some problems, here are the ones that I don't know how to deal with:...
2
by: Simon Harris | last post by:
I have created a web service, which when I call in my browser presents the text form etc. When I click the button, I get this error: System.ArgumentException: Cannot convert to System.Int32....
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
3
by: kaizen | last post by:
Hi, i wrote the code in C and compiled in VC++ compiler. at that time it has thrown the below mentioned error. error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *'...
2
by: keithb | last post by:
A web site published from its development environment (VS Web Server) to an IIS 6.0 site displays this message: Compiler Error Message: CS0030: Cannot convert type 'ASP.login_aspx' to...
1
by: stillh2os | last post by:
Hello. I'm new to .NET, and I'm trying to implement a callback function. I want my managed C++ code to call an unmanaged function, passing in a callback function that the unmanaged C/C++ code...
1
by: td0g03 | last post by:
I have no idea why am I getting an error C2664: 'parseInput' : cannot convert parameter 2 from 'main::WORD_STRUCT ' to 'struct WORD_STRUCT ' #include <stdio.h> #include <stdlib.h> #include...
5
by: slizorn | last post by:
well the error i get is the title above: error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char' error is form this line searchTree(treeObj->root ,data1.c_str());...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...
0
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...

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.