• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 787
  • Last Modified:

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.
0
directxBOB
Asked:
directxBOB
4 Solutions
 
abithCommented:
did you try typecasting it to your data type.
eg:
state->buf = (char*) mymalloc(len+1 /* null terminator */);
0
 
lucky_jamesCommented:
malloc returns a void pointer and ( i think) so does your mymalloc which, perhaps, is overriding malloc function.
0
 
lucky_jamesCommented:
continuing from previous comment......
so i also think that typecasting as
state->buf = (char*) mymalloc(len+1 /* null terminator */);

should do.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
directxBOBAuthor Commented:
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
}

0
 
lucky_jamesCommented:
try it casting as :
  rc =(M_Status) NFastApp_Init(&app_handle, 0, 0, 0, 0);
0
 
Infinity08Commented:
Are you sure you're compiling with a C compiler ? Not with a C++ compiler ?
0
 
directxBOBAuthor Commented:
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      
0
 
lucky_jamesCommented:
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"
0
 
lucky_jamesCommented:
ignore my previous comment, the actual solution seems like just the reverse.

Please ensure that i->o->args has a string to point on.

try :
i->o->args ?(char*) i->o->args : "$p: option `$o' not yet implemented\n"

Hope it helps.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now