directxBOB
asked on
C2440 'conversion' : cannot convert from 'type1' to 'type2' Help
I have a file called tokenise.c it was made in VS 5 so it's a bit old. But I am trying to get it updated to work in 2005
I am getting around 30 C2440 errors and just wondering how I go about fixing them, for example this line:
state->ptr = state->buf = mymalloc(len+1 /* null terminator */);
which is throwing:
Error 1 error C2440: '=' : cannot convert from 'void *' to 'char *' c:\Test2\tokenise.c 22
I've been reading :
http://msdn2.microsoft.com/en-us/library/sy5tsf8z(VS.80).aspx
but still a little unsure as to how to fix my C files without butchering too much.
I am getting around 30 C2440 errors and just wondering how I go about fixing them, for example this line:
state->ptr = state->buf = mymalloc(len+1 /* null terminator */);
which is throwing:
Error 1 error C2440: '=' : cannot convert from 'void *' to 'char *' c:\Test2\tokenise.c 22
I've been reading :
http://msdn2.microsoft.com/en-us/library/sy5tsf8z(VS.80).aspx
but still a little unsure as to how to fix my C files without butchering too much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
malloc returns a void pointer and ( i think) so does your mymalloc which, perhaps, is overriding malloc function.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Type Casting worked for all of them except:
Error 15 error C2440: '=' : cannot convert from 'int' to 'M_Status' c:\Test2\cardset.c 33
M_Status rc;
/* Initialize the application */
rc = NFastApp_Init(&app_handle, 0, 0, 0, 0);
NFastApp_Init returns an int, that matches up with M_Status Enum:
typedef enum M_Status {
Status_OK = 0,
Status_UnknownCommand = 1,
Status_NotYetImplemented = 2,
Status_Malformed = 3
}
Error 15 error C2440: '=' : cannot convert from 'int' to 'M_Status' c:\Test2\cardset.c 33
M_Status rc;
/* Initialize the application */
rc = NFastApp_Init(&app_handle,
NFastApp_Init returns an int, that matches up with M_Status Enum:
typedef enum M_Status {
Status_OK = 0,
Status_UnknownCommand = 1,
Status_NotYetImplemented = 2,
Status_Malformed = 3
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you sure you're compiling with a C compiler ? Not with a C++ compiler ?
ASKER
Cheers
Finally one last one:
nf_printv(stderr, &w, i->o->args ? i->o->args :
"$p: option `$o' not yet implemented\n", i, 0, 0);
Error 11 error C2664: 'nf_printv' : cannot convert parameter 3 from 'const void *const ' to 'const char *' c:\Test2\nfopt.c 470
Finally one last one:
nf_printv(stderr, &w, i->o->args ? i->o->args :
"$p: option `$o' not yet implemented\n", i, 0, 0);
Error 11 error C2664: 'nf_printv' : cannot convert parameter 3 from 'const void *const ' to 'const char *' c:\Test2\nfopt.c 470
here
i->o->args ? i->o->args : "$p: option `$o' not yet implemented\n"
seems the root cause.
looks like 'i->o->args' is of type 'void*'
while "$p: option `$o' not yet implemented\n" is of type 'char*'
try following :
i->o->args ? i->o->args : (void*) "$p: option `$o' not yet implemented\n"
i->o->args ? i->o->args : "$p: option `$o' not yet implemented\n"
seems the root cause.
looks like 'i->o->args' is of type 'void*'
while "$p: option `$o' not yet implemented\n" is of type 'char*'
try following :
i->o->args ? i->o->args : (void*) "$p: option `$o' not yet implemented\n"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.