tags:

views:

296

answers:

4
Error 38 error C2660: 'malloc' : function does not take 1 arguments C:\VolumeRenderer\render.cpp 296 1 VolumeRenderer
Error 39 error C2660: 'malloc' : function does not take 1 arguments C:\VolumeRenderer\render.cpp 412 1 VolumeRenderer
Error 40 error C2660: 'malloc' : function does not take 1 arguments C:\VolumeRenderer\render.cpp 414 1 VolumeRenderer
Error 41 error C2660: 'read_den' : function does not take 4 arguments C:\VolumeRenderer\render.cpp 506 1 VolumeRenderer

My all malloc sections are like this:

/* allocate space for the raw data */
density_size = BRAIN_XLEN * BRAIN_YLEN * BRAIN_ZLEN;
density = (unsigned char*)malloc(density_size);
if (density == NULL) {
  fprintf(stderr, "out of memory\n");
  exit(1);
}

regarding read_den (last error) . read_den does take 4 parameters. You can see the function prototype & its corresponding call here:

  unsigned char *read_den(char *filename,int *xptr,int *yptr,int *zptr)// function prototype
  src_volume = read_den(src_file, &src_xlen, &src_ylen, &src_zlen);// fucntion call

Is it my code or the errors that are absurd. How to rectify them?

EDIT: can some one comment on the last error because. I'm unable to justify it.

EDIT2: When I changed the file extension from *.cpp to *.c then all errors are gone. So, I think it has something to do with C & C++.

+3  A: 

Wild guess: you used malloc incorrectly somewhere else, passing two arguments instead of one. This would result in an implicit declaration.

Try compiling with all warnings enabled and see if anything comes up.


Update: You could also put #include <stlib.h> as the very first line in your source file, so that any potential implicit declaration would be flagged as an error.

Thomas
@Thomas : I enabled /Wall I got around 1600 warning. I did a quick search for 'malloc' in these warnings+errors and Other than the errors I mentioned in question. These are the other two entries that hit my search:`Warning 841 warning C4514: '_MarkAllocaS' : unreferenced inline function has been removed C:\Program Files\Microsoft Visual Studio 10.0\VC\include\malloc.h 192 1 VolumeRenderer`and `Warning 842 warning C4514: '_freea' : unreferenced inline function has been removed C:\Program Files\Microsoft Visual Studio 10.0\VC\include\malloc.h 227 1 VolumeRenderer`
pecker
1600 warnings... maybe something to look into.
Thomas
+1  A: 

Maybe you shadow the real malloc function somewhere in your code. In gcc you can use the -Wshadow flag to test. I am sure there is something similiar in Visual Studio.

Edit: I read the second part you added and the errors seem to come indeed from incompatibilities between C and C++. Depending on the size of your project, this might be tedious work to sort out. I suggest, that you use the "extern" keyword to link your new C++ code to your working C code.

Example:

#include <stdio.h>
#include <stdlib.h>

int cplusplus_function(int a); 

main(){
    printf("c code\n");

    int* a = malloc(sizeof(int)); //just proving that this is indeed C code.
                                  //this would not compile with a C++ compiler

    cplusplus_function(5);
    return 0;
}

and a C++ function with the "extern" keyword:

#include <iostream>

extern "C" void cplusplus_function(int);

void cplusplus_function(int a){
    std::cout << "c++ code" << std::endl;
}

Now you can compile the files separately and link them together.

Lucas
what is this shadowing?
pecker
Shadowing is making something inaccessible by putting something above in its place so the former cannot be seen... You would probably have seen that expression while configuring your computer's BIOS ;-)
fortran
A: 

if it is C++ you should use new and delete instead of malloc and free

knittl
pecker
A: 
  1. Do you have #include <stdlib.h>?
  2. Try generating the preprocessed output (with MSVC, this is done with the /E option). Look through the resulting output for malloc and read_den declarations.
jamesdlin
Thats an intelligent way which didn't struck my mind. :(
pecker
@pecker: So did it help?
jamesdlin