Solved

Verify memory allocated

Posted on 2004-11-01
185 Views
Last Modified: 2010-04-15
Hi,

int *p;
p = (int*)malloc(128);

Is there any mechanism to verify that the specified memory is allocated

Thanks
Yuvvy
0
Question by:YuvrajHSaunshi
    4 Comments
     
    LVL 33

    Accepted Solution

    by:
    try this

    if ( (p = (int*)malloc(128)) == NULL )
    {
        /* error */
    }
    0
     

    Expert Comment

    by:Tirumaleshwar
    if( p != NULL){
    ........ success

    }
    esle
      {
    ...... failure
    }
    0
     
    LVL 7

    Expert Comment

    by:aib_42
    Also, casting the return type of malloc() is a bad idea since it will suppress the warning message should you forget to include stdlib.h, which would result in undefined behaviour.
    0
     
    LVL 33

    Expert Comment

    by:hongjun
    if you are using gcc to compile, use this option to see all warning
        $> gcc -Wall yourfile.c


    hongjun
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now