array subscript type cannot be `char`?

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

    #46
    Re: array subscript type cannot be `char`?

    Jordan Abel schrieb:[color=blue]
    > On 2006-03-27, Michael Mair <Michael.Mair@i nvalid.invalid> wrote:
    >[color=green]
    >>Jordan Abel schrieb:
    >>[color=darkred]
    >>>Note: No context quoted because I'm replying to the actual issue the
    >>>thread brings up rather than to any particular post
    >>>
    >>>What all this is missing is that it's silly to warn on an array
    >>>subscript of type char when you don't warn on one of type signed int.
    >>>
    >>>Idea -- magic safe macro for isalpha:
    >>>
    >>>#define ISALPHA(x) isalpha(sizeof( x)==1?(unsigned char)(x):(x))[/color]
    >>
    >>Hmmm. Nice until x is something with sideeffects like, say,
    >>"c = getchar()".[/color]
    >
    > That's why it's uppercase. To warn you.[/color]

    For functionality as basic as this, I do not trust anyone
    to use it consistently correctly -- including me. I remember
    a then-colleague abusing a macro with the words "Oh, it's
    from XY -- he surely did something clever"... ;-(

    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.

    Comment

    • Jordan Abel

      #47
      Re: array subscript type cannot be `char`?

      On 2006-03-28, Michael Mair <Michael.Mair@i nvalid.invalid> wrote:[color=blue]
      > Jordan Abel schrieb:[color=green]
      >> On 2006-03-27, Michael Mair <Michael.Mair@i nvalid.invalid> wrote:
      >>[color=darkred]
      >>>Jordan Abel schrieb:
      >>>
      >>>>Note: No context quoted because I'm replying to the actual issue the
      >>>>thread brings up rather than to any particular post
      >>>>
      >>>>What all this is missing is that it's silly to warn on an array
      >>>>subscript of type char when you don't warn on one of type signed int.
      >>>>
      >>>>Idea -- magic safe macro for isalpha:
      >>>>
      >>>>#define ISALPHA(x) isalpha(sizeof( x)==1?(unsigned char)(x):(x))
      >>>
      >>>Hmmm. Nice until x is something with sideeffects like, say,
      >>>"c = getchar()".[/color]
      >>
      >> That's why it's uppercase. To warn you.[/color]
      >
      > For functionality as basic as this, I do not trust anyone
      > to use it consistently correctly -- including me. I remember
      > a then-colleague abusing a macro with the words "Oh, it's
      > from XY -- he surely did something clever"... ;-([/color]

      as it turns out, i _did_ do something clever. x is evaluated only once.

      --
      look closer...

      Comment

      • pete

        #48
        Re: array subscript type cannot be `char`?

        Jordan Abel wrote:[color=blue]
        >
        > Note: No context quoted because I'm replying to the actual issue the
        > thread brings up rather than to any particular post
        >
        > What all this is missing is that it's silly to warn on an array
        > subscript of type char when you don't warn on one of type signed int.
        >
        > Idea -- magic safe macro for isalpha:
        >
        > #define ISALPHA(x) isalpha(sizeof( x)==1?(unsigned char)(x):(x))[/color]

        I don't understand what that macro is for, or how you would use it.
        If you would cast a byte sized type to unsigned char,
        why wouldn't you cast a larger type to unsigned char?

        --
        pete

        Comment

        • CBFalconer

          #49
          Re: array subscript type cannot be `char`?

          Jordan Abel wrote:[color=blue]
          > On 2006-03-28, Michael Mair <Michael.Mair@i nvalid.invalid> wrote:[color=green]
          >> Jordan Abel schrieb:[color=darkred]
          >>> On 2006-03-27, Michael Mair <Michael.Mair@i nvalid.invalid> wrote:
          >>>> Jordan Abel schrieb:
          >>>>
          >>>>> Note: No context quoted because I'm replying to the actual
          >>>>> issue the thread brings up rather than to any particular post
          >>>>>
          >>>>> What all this is missing is that it's silly to warn on an
          >>>>> array subscript of type char when you don't warn on one of type
          >>>>> signed int.
          >>>>>
          >>>>> Idea -- magic safe macro for isalpha:
          >>>>>
          >>>>> #define ISALPHA(x) isalpha(sizeof( x)==1?(unsigned char)(x):(x))
          >>>>
          >>>> Hmmm. Nice until x is something with sideeffects like, say,
          >>>> "c = getchar()".
          >>>
          >>> That's why it's uppercase. To warn you.[/color]
          >>
          >> For functionality as basic as this, I do not trust anyone
          >> to use it consistently correctly -- including me. I remember
          >> a then-colleague abusing a macro with the words "Oh, it's
          >> from XY -- he surely did something clever"... ;-([/color]
          >
          > as it turns out, i _did_ do something clever. x is evaluated
          > only once.[/color]

          There you go - somebody finally noticed.

          --
          "If you want to post a followup via groups.google.c om, don't use
          the broken "Reply" link at the bottom of the article. Click on
          "show options" at the top of the article, then click on the
          "Reply" at the bottom of the article headers." - Keith Thompson
          More details at: <http://cfaj.freeshell. org/google/>
          Also see <http://www.safalra.com/special/googlegroupsrep ly/>

          Comment

          • Jordan Abel

            #50
            Re: array subscript type cannot be `char`?

            On 2006-03-28, pete <pfilandr@minds pring.com> wrote:[color=blue]
            > Jordan Abel wrote:[color=green]
            >>
            >> Note: No context quoted because I'm replying to the actual issue the
            >> thread brings up rather than to any particular post
            >>
            >> What all this is missing is that it's silly to warn on an array
            >> subscript of type char when you don't warn on one of type signed int.
            >>
            >> Idea -- magic safe macro for isalpha:
            >>
            >> #define ISALPHA(x) isalpha(sizeof( x)==1?(unsigned char)(x):(x))[/color]
            >
            > I don't understand what that macro is for, or how you would use it.
            > If you would cast a byte sized type to unsigned char,
            > why wouldn't you cast a larger type to unsigned char?[/color]

            Because the larger type is likely to be an int which is safe to use
            since it will be valued either EOF or between 0 and UCHAR_MAX [e.g. the
            result from getc] the issue is that a char value could be a negative
            number other than EOF.

            Comment

            • Michael Mair

              #51
              Re: array subscript type cannot be `char`?

              Jordan Abel schrieb:[color=blue]
              > On 2006-03-28, Michael Mair <Michael.Mair@i nvalid.invalid> wrote:
              >[color=green]
              >>Jordan Abel schrieb:
              >>[color=darkred]
              >>>On 2006-03-27, Michael Mair <Michael.Mair@i nvalid.invalid> wrote:
              >>>
              >>>
              >>>>Jordan Abel schrieb:
              >>>>
              >>>>
              >>>>>Note: No context quoted because I'm replying to the actual issue the
              >>>>>thread brings up rather than to any particular post
              >>>>>
              >>>>>What all this is missing is that it's silly to warn on an array
              >>>>>subscrip t of type char when you don't warn on one of type signed int.
              >>>>>
              >>>>>Idea -- magic safe macro for isalpha:
              >>>>>
              >>>>>#define ISALPHA(x) isalpha(sizeof( x)==1?(unsigned char)(x):(x))
              >>>>
              >>>>Hmmm. Nice until x is something with sideeffects like, say,
              >>>>"c = getchar()".
              >>>
              >>>That's why it's uppercase. To warn you.[/color]
              >>
              >>For functionality as basic as this, I do not trust anyone
              >>to use it consistently correctly -- including me. I remember
              >>a then-colleague abusing a macro with the words "Oh, it's
              >>from XY -- he surely did something clever"... ;-([/color]
              >
              > as it turns out, i _did_ do something clever. x is evaluated only once.[/color]

              You are right -- my bad.

              Cheers
              Michael
              --
              E-Mail: Mine is an /at/ gmx /dot/ de address.

              Comment

              • Jordan Abel

                #52
                Re: array subscript type cannot be `char`?

                On 2006-03-28, Michael Mair <Michael.Mair@i nvalid.invalid> wrote:[color=blue]
                > Jordan Abel schrieb:[color=green]
                >> On 2006-03-28, Michael Mair <Michael.Mair@i nvalid.invalid> wrote:
                >>[color=darkred]
                >>>Jordan Abel schrieb:
                >>>
                >>>>On 2006-03-27, Michael Mair <Michael.Mair@i nvalid.invalid> wrote:
                >>>>
                >>>>
                >>>>>Jordan Abel schrieb:
                >>>>>
                >>>>>
                >>>>>>Note: No context quoted because I'm replying to the actual issue the
                >>>>>>thread brings up rather than to any particular post
                >>>>>>
                >>>>>>What all this is missing is that it's silly to warn on an array
                >>>>>>subscri pt of type char when you don't warn on one of type signed int.
                >>>>>>
                >>>>>>Idea -- magic safe macro for isalpha:
                >>>>>>
                >>>>>>#define ISALPHA(x) isalpha(sizeof( x)==1?(unsigned char)(x):(x))
                >>>>>
                >>>>>Hmmm. Nice until x is something with sideeffects like, say,
                >>>>>"c = getchar()".
                >>>>
                >>>>That's why it's uppercase. To warn you.
                >>>
                >>>For functionality as basic as this, I do not trust anyone
                >>>to use it consistently correctly -- including me. I remember
                >>>a then-colleague abusing a macro with the words "Oh, it's
                >>>from XY -- he surely did something clever"... ;-([/color]
                >>
                >> as it turns out, i _did_ do something clever. x is evaluated only once.[/color]
                >
                > You are right -- my bad.[/color]

                I didn't realize it at first either, it's easy to miss.

                Comment

                Working...