Thread: compiling c code

  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,218
    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.
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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, 12:50 PM
  2. Replies: 1
    Last Post: 03-01-2006, 03: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, 01: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-16-2002, 12:04 AM