0
    for( k = 0; k < CycleCount;k++)
    {
        //make Org data
        int* Data = MakeData(DataCount[i]);
  ......

the function look like this one. i think this is right. so ...

  int* MakeData(int DataCount)
  {
        //
   int* Data=(int*)malloc(DataCount*sizeof(int));
   int i;
   for( i=0; i<DataCount; i++)
   {
      //
      Data[i] = rand()%DataCount +1;
   }
   return Data;
 }

i dont know why this didn't work.

what shoud i have to do???

5
  • 1
    Which line is the warning from? Commented Apr 9, 2014 at 13:15
  • For which line do you get this warning ? Commented Apr 9, 2014 at 13:15
  • 2
    ...and what is DataCount ? Commented Apr 9, 2014 at 13:16
  • @MichaelWalz The symbol name DataCount is obviously used multiple times: 1. in the function MakeData it's an integer parameter, 2. Somewhere else where MakeData is called it's something else. Commented Apr 9, 2014 at 13:25
  • @harper: sure, but I implicitly meant the one in int* Data = MakeData(DataCount[i]), the other one being defined as a parameter in MakeData. I should have been more explicit. Commented Apr 9, 2014 at 13:30

1 Answer 1

5

When the C compiler finds a function call without having seen a function prototype it assumes a function that returns an int.

You should tell the compiler the correct function signature with the "function prototype":

int* MakeData(int DataCount);

This should be placed in a .h file that will be included in all compilation units that call or define the function.

If you have a static function, that is visible only in the current compilation unit, you can place the prototype (incl. static) before all functions in that file.

Further you should never cast the return from malloc. It returns a void*. In the language C this can be converted to any other pointer type. You get the correct prototype when you #include <stdlib.h>.

Sign up to request clarification or add additional context in comments.

5 Comments

I was about to answer :) This is the only one that is clear from the question.
@harper, your comment about my deleted answer is right, but for a slightly different reason. DataCount[i] is supposed to be equivalent *(DataCount + i). But if you wrote that it would give you an true error, and not just try to implicitly cast it to a pointer-to-int.
@AdrianRatnapala Sorry, I can't read neither your deleted answer nor my comment anymore.
@Harper, sorry about that. My answer was flat wrong, so I want it deleted. But FYI: you said that MakeData() was expecting an int, not a pointer. And my (wrong) theory was that it was, indeed getting an int, but that the dereferencing process involved an implicit int-to-pointer conversion.
@AdrianRatnapala Don't worry, be happy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.