Like Tree3Likes

Pointers to pointers

This is a discussion on Pointers to pointers within the C++ Programming forums, part of the General Programming Boards category; It's better to do this by the way: Code: char **temp = realloc( count * sizeof(stringList) ); if ( temp ...

  1. #16
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    It's better to do this by the way:

    Code:
    char **temp = realloc( count * sizeof(stringList) );
    if ( temp != NULL ) {
       stringList = temp;
    }
    else {
       free( stringList );
       logerrors(  );
    }
    The reason is because if realloc fails, it will return NULL. You would leak the old memory if you simply reassigned like you did.

    Although I agree that if you're right and the string object doesn't work, you ought to make your own string object that has the inner workings you require. That way you can just do:

    psychoxixString stringList[ MAX ]; or whatever is actually appropriate.
    rags_to_riches likes this.

  2. #17
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    If you cannot use the MSVC version of the STL perhaps you could use STL port? I actually recommend using it even if you can use the MSVC STL.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. size of struct with pointers and function pointers
    By sdsjohnny in forum C Programming
    Replies: 3
    Last Post: 07-02-2010, 05:19 AM
  2. Storing function pointers in generic pointers
    By Boxknife in forum C Programming
    Replies: 6
    Last Post: 08-01-2009, 01:33 PM
  3. Variable pointers and function pointers
    By Luciferek in forum C++ Programming
    Replies: 11
    Last Post: 08-02-2008, 02:04 AM
  4. Pointers to objects -- passing and returning pointers
    By 1veedo in forum C++ Programming
    Replies: 4
    Last Post: 04-04-2008, 11:42 AM
  5. weak pointers and use_count smart pointers
    By Mario F. in forum C++ Programming
    Replies: 2
    Last Post: 07-29-2006, 07:54 AM

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