perror question

Discussion in 'C Programming' started by Clunixchit, Jun 19, 2005.

  1. Clunixchit

    Clunixchit Guest

    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
     
    Clunixchit, Jun 19, 2005
    #1
    1. Advertising

  2. Clunixchit

    SM Ryan Guest

    -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.

    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    Who's leading this mob?
     
    SM Ryan, Jun 19, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    774
  2. L. Westmeier

    When to use "perror" and "fprintf"

    L. Westmeier, May 4, 2004, in forum: C Programming
    Replies:
    6
    Views:
    743
    OSHIMA
    May 13, 2004
  3. Martin
    Replies:
    7
    Views:
    693
    Chris Torek
    Dec 9, 2004
  4. puzzlecracker

    cout and perror

    puzzlecracker, Oct 22, 2005, in forum: C++
    Replies:
    3
    Views:
    346
    Branimir Maksimovic
    Oct 23, 2005
  5. Guillaume Dargaud

    Redirecting perror

    Guillaume Dargaud, Aug 7, 2007, in forum: C Programming
    Replies:
    12
    Views:
    1,198
    Keith Thompson
    Aug 8, 2007
Loading...

Share This Page