Like Tree2Likes
  • 2 Post By itsme86

dereferencing void pointers in my realloc

This is a discussion on dereferencing void pointers in my realloc within the C Programming forums, part of the General Programming Boards category; hi, can anyone tell me how to get around these problems? the two problems is: 1. dereferencing "void *"-pointer 2. ...

  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,175
    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);
    }
    mattholm and CommonTater like this.
    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, 07:17 AM
  3. dereferencing void pointer
    By nkhambal in forum C Programming
    Replies: 4
    Last Post: 04-25-2005, 03:47 AM
  4. dereferencing a void pointer
    By cricket in forum C Programming
    Replies: 8
    Last Post: 09-12-2003, 05:09 PM
  5. dereferencing a void *
    By pointing in forum C++ Programming
    Replies: 9
    Last Post: 12-06-2002, 02:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21