C2440 'conversion' : cannot convert from 'type1' to 'type2' Help

Posted on 2007-10-18
Last Modified: 2008-01-09
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 :

but still a little unsure as to how to fix my C files without butchering too much.
Question by:directxBOB
    LVL 5

    Accepted Solution

    did you try typecasting it to your data type.
    state->buf = (char*) mymalloc(len+1 /* null terminator */);
    LVL 7

    Expert Comment

    malloc returns a void pointer and ( i think) so does your mymalloc which, perhaps, is overriding malloc function.
    LVL 7

    Assisted Solution

    continuing from previous comment......
    so i also think that typecasting as
    state->buf = (char*) mymalloc(len+1 /* null terminator */);

    should do.

    Author Comment

    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

    LVL 7

    Assisted Solution

    try it casting as :
      rc =(M_Status) NFastApp_Init(&app_handle, 0, 0, 0, 0);
    LVL 53

    Expert Comment

    Are you sure you're compiling with a C compiler ? Not with a C++ compiler ?

    Author Comment


    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      
    LVL 7

    Expert Comment

    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"
    LVL 7

    Assisted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now