compiling c code

This is a discussion on compiling c code within the C++ Programming forums, part of the General Programming Boards category; Im getting this error: error C2440: 'initializing' : cannot convert from 'void *' to 'float (*)[3]' Conversion from 'void*' to ...

  1. #1
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735

    compiling c code

    Im getting this error:
    error C2440: 'initializing' : cannot convert from 'void *' to 'float (*)[3]'
    Conversion from 'void*' to pointer to non-'void' requires an explicit cast
    from
    Code:
    Lib3dsVector *normalL = malloc(3*sizeof(Lib3dsVector)*mesh->faces);
    That's standard code for lib3ds so I think the problem is that it's c code being compiled in a cpp file. Can I specify that line to be compiled as c, or maybe there's another solution?

    Thanks,
    MadCow

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    The difference betwean C and C++ is that C allows you to convert betwean a normal pointer to a void pointer without a cast, that is not the case in C++. As far as i know you will have to stick to cast the return value from malloc. Of course you could make it easier by doing stuff like create a template function that wraps the cast and call to malloc but you will still have to perform the cast.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    Yes, compile it as C, then read this
    http://www.parashift.com/c++-faq-lit...c-and-cpp.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. loop and compiling inside a code
    By MtJ in forum C Programming
    Replies: 3
    Last Post: 03-05-2006, 11:50 AM
  2. Replies: 1
    Last Post: 03-01-2006, 02:07 AM
  3. Seems like correct code, but results are not right...
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 12:33 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 4
    Last Post: 01-15-2002, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21