perror question

C

Clunixchit

Im writing a program in which i have to perform several mallocs

in order to simply my code i have used
void e_malloc(){
perror("malloc");
_exit(EXIT_FAILURE);
}

if ( !(phrase.T = malloc ( sizeof *(phrase.T)
)))
e_malloc();
instead of
[code:1:c9ebbe2331]if ( !(phrase.T = malloc ( sizeof
*(phrase.T) ))) {
perror("malloc");
_exit(EXIT_FAILURE);
}[/code:1:c9ebbe2331]
my question is, does perror wld still contain the errno message if the
malloc fails
 
S

SM Ryan

(e-mail address removed)-spam.invalid (Clunixchit) wrote:

# my question is, does perror wld still contain the errno message if the
# malloc fails

errno is a global variable (or looks like a global variable). If set by
malloc it will have the same value in all other functions that reference
it until set to a new value. It won't be changed by simply calling another
function.

perror() references the current value of errno.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top