Thread: dereferencing void pointers in my realloc

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    19

    dereferencing void pointers in my realloc

    hi, can anyone tell me how to get around these problems?
    the two problems is:
    1. dereferencing "void *"-pointer
    2. the value of the type void is not ignored, as it should.

    Code:
    /*realloc: change size of the allocated memoryblock*/
    void *realloc(void *oldp, size_t size)
    {
    
        if (*oldp == NULL){    /*if NULL then use malloc*/
            return(malloc(size));
        }
    thanks!

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Well, first of all, you want to use function names that aren't already used in the standard library. Secondly, you don't want to check if *oldp is NULL, you want to just see if oldp is NULL. So it should probably be something like:
    Code:
    void *my_realloc(void *oldp, size_t size)
    {
      if(oldp == NULL)
        return malloc(size);
    }
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dereferencing a Void Pointer in a Structure
    By simpsonseric in forum C Programming
    Replies: 5
    Last Post: 01-17-2009, 04:58 PM
  2. Warning:dereferencing `void *' pointer
    By g_p in forum C Programming
    Replies: 8
    Last Post: 04-26-2007, 06:17 AM
  3. dereferencing void pointer
    By nkhambal in forum C Programming
    Replies: 4
    Last Post: 04-25-2005, 02:47 AM
  4. dereferencing a void pointer
    By cricket in forum C Programming
    Replies: 8
    Last Post: 09-12-2003, 04:09 PM
  5. dereferencing a void *
    By pointing in forum C++ Programming
    Replies: 9
    Last Post: 12-06-2002, 02:38 PM