Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #43624

Re: errno

From "Bill Cunningham" <nospam@nspam.invalid>
Newsgroups comp.lang.c
Subject Re: errno
Date 2014-04-26 20:23 -0400
Organization A noiseless patient Spider
Message-ID <ljhin0$ldl$1@dont-email.me> (permalink)
References <ljh687$b06$1@dont-email.me> <dsgol9h34hqo6q4jk00fl6boj6mneb6n4v@4ax.com>

Show all headers | View raw


"Barry Schwarz" <schwarzb@dqel.com> wrote in message 
news:dsgol9h34hqo6q4jk00fl6boj6mneb6n4v@4ax.com...
> On Sat, 26 Apr 2014 16:51:17 -0400, "Bill Cunningham"
> <nospam@nspam.invalid> wrote:
>
>>    My little utility doesn't print an errno value like it should. I have
>
> Nowhere in your code do you attempt to print the value of errno.
>
>>tried to fix it but have failed. I've never really used errno.h but always
>>perror() so what am I doing wrong here.
>>
>>#include <stdio.h>
>>#include <stdlib.h>
>>#include <errno.h>
>>#include <string.h>
>>
>>int main(int argc, char *argv[])
>>{
>>    long int a;
>>    errno = 0;
>>    if ((a = strtol(argv[1], NULL, 16)) == -1)
>
> According to your follow-up message, argv[1] is a string consisting of
> 15 f's.  Under what conditions do you think this would ever produce a
> value of -1?  (You should read the description of strtol and determine
> the only situation when it can produce a negative value.)
>
> What is the size of long int on your system?  How did you determine
> this?
>
>>        printf("%s\n", strerror(errno));
>
> What makes you think errno was set by anything your program did?
>
>>    printf("%d\n", a);
>
> This undefined behavior has been addressed by others.
>
>>    return 0;
>>}

    Works fine now. I've never used strtol or strtoll. I have occasssionally 
used strtod and had great success. errno seems to set to ERANGE now when I 
intentionally try to over or underflow. I am in the habit of -1 as in most 
*nix sys calls being an error. I admit I should've look closer at the man 
page.

Bill

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

errno "Bill Cunningham" <nospam@nspam.invalid> - 2014-04-26 16:51 -0400
  Re: errno Eric Wolf <eric@boese-wolf.eu> - 2014-04-26 23:11 +0200
    Re: errno "Bill Cunningham" <nospam@nspam.invalid> - 2014-04-26 17:17 -0400
      Re: errno Ike Naar <ike@iceland.freeshell.org> - 2014-04-26 22:35 +0000
        Re: errno "Bill Cunningham" <nospam@nspam.invalid> - 2014-04-26 19:35 -0400
  Re: errno Richard <rgrdev_@gmail.com> - 2014-04-26 23:56 +0200
  Re: errno Barry Schwarz <schwarzb@dqel.com> - 2014-04-26 17:15 -0700
    Re: errno "Bill Cunningham" <nospam@nspam.invalid> - 2014-04-26 20:23 -0400
      Re: errno "Bill Cunningham" <nospam@nspam.invalid> - 2014-04-26 20:27 -0400
    Re: errno "Bill Cunningham" <nospam@nspam.invalid> - 2014-04-26 20:42 -0400

csiph-web