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

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


  2. #2
    Registered User
    Join Date
    Aug 2003
    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
    The edge of the known universe
    Yes, compile it as C, then read this

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