errno

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RoSsIaCrIiLoIA

    #1

    errno

    On Wed, 05 May 2004, CBFalconer <cbfalconer@yah oo.com> wrote:
    [color=blue]
    >Even if sscanf succeeds in inputting various fields, there are
    >probably range and other validity checks to be applied. The
    >interactive programmers work is never done :-)[/color]

    in how I see it errno (or errno like) would have 32 states
    0 /* No error */
    1u, 2u, 4u, 8u, 16u, 32u, 64u, 128u, 256u, 512u, 1024u, 2048u
    4096u, 8192u, 16384u, 32768u, 65536u, 131072u, 262144u,
    524288u, 1048576u, 2097152u, 4194604u, 8388608u, 16777216u,
    33554432u, 67108864u, 134217728u, 268435456u, 5356870912u,
    1073741824u, 2147483648u. /* code error */

    because seems to me that errors *sum themselves*
    but are they enough ?
    if(error_find_x xtype) errno |= error_find_xxty pe;
    Is there someone that reads my posts?

  • Robert W Hand

    #2
    Re: errno

    On Wed, 05 May 2004 07:13:45 GMT, RoSsIaCrIiLoIA <n@esiste.ee> wrote:
    [color=blue]
    >On Wed, 05 May 2004, CBFalconer <cbfalconer@yah oo.com> wrote:
    >[color=green]
    >>Even if sscanf succeeds in inputting various fields, there are
    >>probably range and other validity checks to be applied. The
    >>interactive programmers work is never done :-)[/color]
    >
    >in how I see it errno (or errno like) would have 32 states
    >0 /* No error */
    >1u, 2u, 4u, 8u, 16u, 32u, 64u, 128u, 256u, 512u, 1024u, 2048u
    >4096u, 8192u, 16384u, 32768u, 65536u, 131072u, 262144u,
    >524288u, 1048576u, 2097152u, 4194604u, 8388608u, 16777216u,
    >33554432u, 67108864u, 134217728u, 268435456u, 5356870912u,
    >1073741824u, 2147483648u. /* code error */[/color]

    The error values of errno are of type int, not unsigned int. errno is
    a macro or identifier with external linkage, that expands into a
    modifiable lvalue. It has type int, and it is set equal to zero at
    program startup. Positive numbers in the range of int are error
    numbers, but I am not aware that the standard specifies any particular
    number as one of the error numbers. The actual values are hidden by
    the use of macros. The standard library uses errno to warn of an
    error condition in some of the library functions such as EDOM for a
    domain error in log().
    [color=blue]
    >because seems to me that errors *sum themselves*
    >but are they enough ?
    >if(error_find_ xxtype) errno |= error_find_xxty pe;
    >Is there someone that reads my posts?[/color]

    I do not believe that you can or together errno errors. Perhaps you
    have confused the values of math_errhandlin g that can be or'ed
    together. The floating point exceptions macros can be or'ed together,
    too.
    --

    Best wishes,

    Bob

    Comment

    • RoSsIaCrIiLoIA

      #3
      Re: errno

      On Wed, 05 May 2004 07:13:45 GMT, RoSsIaCrIiLoIA <n@esiste.ee> wrote:
      [color=blue]
      >On Wed, 05 May 2004, CBFalconer <cbfalconer@yah oo.com> wrote:
      >[color=green]
      >>Even if sscanf succeeds in inputting various fields, there are
      >>probably range and other validity checks to be applied. The
      >>interactive programmers work is never done :-)[/color][/color]

      #include <stdio.h>
      #include <stdint.h>

      uint8_t errnov[16];

      #define IN_FLAGS 0
      #define OUT_FLAGS 1
      #define ERR_FLAGS 2
      #define MATH_FLAGS 3
      #define FILE_FLAGS 4
      #define DEVICE_FLAGS 5
      #define SIGNALS_FLAGS 6
      #define SYS_FLAGS 7
      #define PROC_FLAGS 8
      /* etc etc */

      /* IN FLAGS */
      #define IN_ERR 16u
      #define IN_RANGE_ERR 8u
      #define IN_EOF 4u
      #define IN_UNGET 2u
      #define IN_NONUM 1u

      int main(void)
      {int i;
      printf("Inseris ci un intero >"); fflush(stdout);
      errnov[IN_FLAGS]=0;
      scanf("%d", &i);
      if(errnov[IN_FLAGS] & (IN_NONUM | IN_RANGE_ERR))
      {
      printf("errore\ n");
      }
      else printf("i=%i\n" , i);
      return 0;
      }

      Comment

      • RoSsIaCrIiLoIA

        #4
        Re: errno

        On Wed, 05 May 2004 14:39:45 GMT, RoSsIaCrIiLoIA <n@esiste.ee> wrote:[color=blue]
        >int main(void)
        >{int i;
        > printf("Inseris ci un intero >"); fflush(stdout);
        > errnov[IN_FLAGS]=0;
        > scanf("%d", &i);
        > if(errnov[IN_FLAGS] & (IN_NONUM | IN_RANGE_ERR))
        > {
        > printf("errore\ n");
        > }
        > else printf("i=%i\n" , i);
        > return 0;
        >}[/color]

        if "throw eccezione" == "errno[IN_FLAGS] |= eccezione"
        this seems to me like the C++

        int main(void)
        {int i;

        printf("Inseris ci un intero >"); fflush(stdout);
        try
        {
        scanf("%d", &i);
        }
        catch(IN_NONUM)
        {
        printf("errore\ n");
        return 0;
        }
        catch(IN_RANGE_ ERR)
        {
        printf("errore\ n");
        return 0;
        }
        printf("i=%i\n" , i);
        return 0;
        }

        Comment

        Working...