Casting a pointer to an int

I am writing my own functions for malloc and free in C for an assignment. I need to take advantage of the C sbrk() wrapper function. From what I understand sbrk() increments the program’s data space by the number of bytes passed as an argument and points to the location of the program break.

If I have the following code snippet:

#define BLOCK_SIZE 20

int x;

x = (int)sbrk(BLOCK_SIZE + 4);

I get the compiler error warning: cast from pointer to integer of different size. Why is this and is there anyway I can cast the address pointed to by sbrk() to an int?

Leave a Comment