Yes, for the N'th time, i am including stdlib.h

Sorry you are getting frustrated :-)

What can I say, the compiler error indicates that the compiler thinks that malloc returns int, that means that for some reason the compiler has not see the declaration of malloc possible reasons are

  • stdlib.h not included, either actually no #include statement or for some reason the #include statement is not being parsed

  • Include protection for stdlib.h defined before including stdlib.h
  • An edit in stadlib.h has removed the declaration of malloc
  • Something I can't think of.

However "assignment makes pointer from integer without a cast" is not an error that you should fix with a cast unless you are specifically expecting to have to convert an integer to a pointer.

If you post the compilable unit producing the error I will see if I can work out what it is.

Here is the code...

# include <stdio.h>
# include <stdlib.h>    //<-------------STDLIB.H---------------

int main()
{
    int * element = malloc(sizeof(int));
    int * array   = calloc(5,sizeof(int));

    element = 5;

    printf("ELEMENT - %d", element);

    free(element);
    free(array);

    return EXIT_SUCCESS;
}

And I've attached my stdlib.h

A-ha. When I compile that code I get these errors

main.c|9|warning: assignment makes pointer from integer without a cast|
main.c|11|warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int *’|

It might have beed a good idea to let us know that the "assignment makes pointer from integer" warning was not actually on the line of code that called malloc or calloc.

The malloc and calloc calls in this code are completely fine. I leave as an exercise for you (initially) to work out what is wrong on the indicated lines 9 and 11.

Aww c**p! Forgot to give those teeny weeny things. Should it be like this?

# include <stdio.h>
# include <stdlib.h>    //<-------------STDLIB.H---------------
 
int main()
{
    int * element = malloc(sizeof(int));
    int * array   = calloc(5,sizeof(int));
 
    *element = 5;
 
    printf("ELEMENT - %d", *element);
 
    free(element);
    free(array);
 
    return EXIT_SUCCESS;
}

Slipped outta my mind that element is a pointer

Okay, here is my last problem in this thread. Sorry for wasting your time like this.
It's related to code blocks. Now i generally do stand alone programs, that is, i don't include them in projects. So, then how do force the compiler to compile my files in C instead of C++?

Code::Blocks is just a light IDE that calls out to gcc so you can just put the compiler switch I gave in post #24 onto you command line