473,386 Members | 1,873 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,386 software developers and data experts.

File pointers and compile error c2440

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:
--------------------------------------------------------------------------
....

.... \myfile.cpp(987) : error C2440: 'initializing' : cannot convert from
'int (__cdecl *)(mytype *,char *,int)' to 'int (__cdecl *)(void)'

None of the functions with this name in scope match the target type

....

----------------------------------------------------------------------------
-------------------------------------------------

The above error happened on a file pointer variable (on each function
address), which is as follows:

------------------------------

int (*fsm_ptr [ OP_MAX + 1 ] [ OP_MAX + 1 ] ) () = {

fsm_invalid, /* [sent = 0] [recv = OP_RRQ] */ // Line 987!

fsm_recv_RRQ, /* [sent = 0] [recv = OP_RRQ] */

fsm_recv_WRQ, /* [sent = 0] [recv = OP_WRQ] */

....

m_invalid, /* [sent = OP_ERROR] [recv = OP_DATA] */

fsm_invalid, /* [sent = OP_ERROR] [recv = OP_ACK] */

fsm_error /* [sent = OP_ERROR] [recv = OP_ERROR] */

};

The pointer variable was used in the main file like this:

....

retVal = (*fsm_ptr[pTd->op_sent][pTd->op_recv])(pTd,

pTd->recvbuff + OPCODE_BYTE_SIZE, nbytes - OPCODE_BYTE_SIZE);

....

--------------------------

Each function in the pointer is declared/implemented in the same file and
returns 0, -1, or -2. For example:

static int

fsm_invalid(struct mytype *pTd, char *ptr, int nbytes)

{

....
return ABORT;//Defined as -2

}

Can anybody help?
Thanks,

Peter


Nov 16 '05 #1
3 3156
Hi Peter,

Thanks for you posting in the group!

I think you had better to specify the full arguments type for the
declaration of function pointer:

int (*fsm_ptr [ OP_MAX + 1 ] [ OP_MAX + 1 ] ) (mytype *,char *,int) = {...
BTW, Does your original C program compile OK under some C compiler?
Best regards,
Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

Nov 16 '05 #2
Gary,

Thank you for your attention.

You are right, the compile error is gone when I changed to full arguments
type for the declaration of function pointer.

Now there is no compile error, but a fatal link error.

"mainserv.obj : fatal error LNK1235: corrupt or invalid COFF symbol table"

The original program works fine. I don't what c compiler the previous owner
used to compile it.

The mainserv.cpp is the main service file (thread managements, invoking
etc.). Her are some settings on the project (properties):
----------------------------------------------------------
....
C/C++
...
Preprocessor/processor Definitions: WIN32;_DEBUG
...
Precompiled Headers/Create/Use Prrecompiled Header: Not Using
Precompiled Headers
...
Advanced/Calling Convention:__cdecl (/Gd)
/Compile As:Compile as C++ Code (/TP)
...
....
------------------------------------------------------------

Not sure if this is the area I should look at.

Thanks,
Peter


"Gary Chang [MSFT]" <v-******@online.microsoft.com> wrote in message
news:y6*************@cpmsftngxa06.phx.gbl...
Hi Peter,

Thanks for you posting in the group!

I think you had better to specify the full arguments type for the
declaration of function pointer:

int (*fsm_ptr [ OP_MAX + 1 ] [ OP_MAX + 1 ] ) (mytype *,char *,int) = {...
BTW, Does your original C program compile OK under some C compiler?
Best regards,
Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 16 '05 #3
Hi Peter,

Thanks for your response!

If you have built your project with /clr option, you can refer to the
following KB article:

PRB: LNK1254, LNK1284 and LNK1235 Linker Errors May Occur While Compiling a
C Source File with the /clr Compiler Option
http://support.microsoft.com/default...b;en-us;822329

Hope that helps!
Best regards,
Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

Nov 16 '05 #4

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

Similar topics

17
by: BlindHorse | last post by:
Help!!! I need someone to tell me why I am getting the err msg error C2440: '=' : cannot convert from 'char *' to 'char' //==================== #include <iostream>
2
by: Steve | last post by:
I am trying to get a handle on function pointers, trying this example program in Visual Studio: #include <iostream.h> class TestingUp { public: TestingUp() {
6
by: Jim | last post by:
I'd like to create a map of strings to member function pointers, so that I can call a specific function based on a string. I'm compiling this using MS Visual C++ 7.0 (VS.NET 2002) class Foo; ...
53
by: Alf P. Steinbach | last post by:
So, I got the itch to write something more... I apologize for not doing more on the attempted "Correct C++ Tutorial" earlier, but there were reasons. This is an UNFINISHED and RAW document,...
11
by: Marc Pelletier | last post by:
Hello, I am having trouble implementing the following callback: CNCSError CECWCompressor::WriteReadLine(UINT32 nNextLine, void **ppInputArray) where ppInputArray is a 3 by x array. The...
5
by: jwright | last post by:
I have decided to use a struct to collect my data. The input file is comma dilineated between almost all of the fields. Here is the code I have so far and a sample input and output file. ...
10
by: d3x0xr | last post by:
---- Section 1 ---- ------ x.c int main( void ) { char **a; char const *const *b; b = a; // line(9)
6
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have a native C++ pointer object which I need to hold in a C# environment, initialize in the C++ environment and the pass between the C# and C++ environments. Which is the data structure to use?...
2
BSCode266
by: BSCode266 | last post by:
Hi, This is some code in the first class: //the array of pointers Slot *slots; //the get method for the previous array //The first error occurs here: error C2440: 'return' : cannot...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.