简体   繁体   中英

How do I call function that has pointer before it

I am struggling with calling function that has pointer before it. We have school project to code our own malloc version. Problem is following:

I call function like this: char *ptrr = (char*)memory_alloc(10);

Function header is this: void *memory_alloc(unsigned int size)

And i get fault like this: Cast from pointer to integer of different size.

Thanks for any ideas.

Your compiler suspects that you are trying to cast a pointer to an integer.
Usually, we get this warning when we try to write something like this:

void myFunction (int i) 
{
    // ....
}

int main()
{
    void *p; // = NULL, malloc, calloc, ...

    myFunction ( (int) p);

    return 0;
}

I suggest you look in your code (ideally post it in your question), if you don't have a cast like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM