Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Verify memory allocated

Posted on 2004-11-01
6
Medium Priority
?
231 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
Comment
Question by:YuvrajHSaunshi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 33

Accepted Solution

by:
hongjun earned 100 total points
ID: 12470531
try this

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

Expert Comment

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

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

Expert Comment

by:aib_42
ID: 12517075
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
ID: 12517448
if you are using gcc to compile, use this option to see all warning
    $> gcc -Wall yourfile.c


hongjun
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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 how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

618 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