Thread: Correct usage of malloc()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by ahluka
    That's good to know. What about reinterpret_cast? Is it the same as a standard C cast?

    Code:
    int* data = (int*) malloc(10); 
     
    int* data = reinterpret_cast<int*> (malloc(10));
    ??
    static_cast is same as C cast
    taken from MSDN:
    The reinterpret_cast operator allows any pointer to be converted into any other pointer type. It also allows any integral type to be converted into any pointer type and vice versa

    The static_cast operator converts expression to the [casted type] based solely on the types present in the expression. No run-time type check is made to ensure the safety of the conversion.r

    The const_cast operator can be used to remove the const, volatile, and __unaligned attribute(s) from a class.

    [and for completeneess]

    The expression dynamic_cast<type-id>( expression ) converts the operand expression to an object of type type-id. The type-id must be a pointer or a reference to a previously defined class type or a pointer to void.
    There is a more detail explanation on each specific MSDN page and I'd encourage you to read them fully.

    http://msdn.microsoft.com/library/de...express_71.asp

  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Thanks for all your replies
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random number + guessing game trouble
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-08-2007, 03:33 AM
  2. Is there a limit on the number of malloc calls ?
    By krissy in forum Windows Programming
    Replies: 3
    Last Post: 03-19-2006, 12:26 PM
  3. quick malloc question
    By thedoofus in forum C Programming
    Replies: 2
    Last Post: 10-15-2005, 05:41 AM
  4. Simple Question on Correct Usage of memset
    By deadpoet in forum C++ Programming
    Replies: 2
    Last Post: 03-16-2004, 08:58 AM