Signed?

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

    Signed?


    int a;

    short b;

    long c;

    char d;


    According to the Standard, are the above signed or unsigned?


    -JKop
  • Pete C.

    #2
    Re: Signed?

    JKop wrote:[color=blue]
    > int a;
    >
    > short b;
    >
    > long c;
    >
    > char d;
    >
    >
    > According to the Standard, are the above signed or unsigned?
    >
    >
    > -JKop[/color]

    int, short and long are, char is implementation defined.
    If you need a signed or unsigned char, use:
    signed char
    or
    unsigned char

    - Pete


    Comment

    • Artie Gold

      #3
      Re: Signed?

      JKop wrote:[color=blue]
      > int a;[/color]

      Yes.[color=blue]
      >
      > short b;[/color]

      Yes.[color=blue]
      >
      > long c;[/color]

      Yes.[color=blue]
      >
      > char d;[/color]

      Maybe (it's implementation dependent).[color=blue]
      >
      >
      > According to the Standard, are the above signed or unsigned?
      >
      >[/color]

      HTH,
      --ag


      --
      Artie Gold -- Austin, Texas

      "What they accuse you of -- is what they have planned."

      Comment

      • Pete C.

        #4
        Re: Signed?

        Pete C. wrote:[color=blue]
        > JKop wrote:[color=green]
        >> int a;
        >>
        >> short b;
        >>
        >> long c;
        >>
        >> char d;
        >>
        >>
        >> According to the Standard, are the above signed or unsigned?
        >>
        >>
        >> -JKop[/color]
        >
        > int, short and long are, char is implementation defined.[/color]

        I mean, int, short and long are signed.

        - Pete
        [color=blue]
        > If you need a signed or unsigned char, use:
        > signed char
        > or
        > unsigned char
        >
        > - Pete[/color]



        Comment

        • Andrey Tarasevich

          #5
          Re: Signed?

          JKop wrote:
          [color=blue]
          > int a;
          >
          > short b;
          >
          > long c;
          >
          > char d;
          >
          >
          > According to the Standard, are the above signed or unsigned?
          > ...[/color]

          Plain 'int', 'short' and 'long' are always equivalent to 'signed int',
          'signed short' and 'signed long', unless used to declare a bit-field (in
          which case it is implementation-defined whether they are signed or
          unsigned).

          A plain 'char' is always a separate type, different (as a type) from
          both 'signed char' and 'unsigned char'. However, the value range of char
          always coincides with value range of either 'signed char' or 'unsigned
          char' (which one - implementation defined). Also, the same comment about
          bit-fields applies to plain 'char' as well.

          --
          Best regards,
          Andrey Tarasevich

          Comment

          • JKop

            #6
            Re: Signed?

            Conforming to the Standard, should the following compile?:


            void Garda(signed short int);

            int main(void)
            {
            short p = 4;

            Garda(p);
            }


            void Garda(short frog)
            {
            frog = 5;
            }

            Comment

            • Andrey Tarasevich

              #7
              Re: Signed?

              JKop wrote:
              [color=blue]
              > Conforming to the Standard, should the following compile?:
              >
              >
              > void Garda(signed short int);
              >
              > int main(void)
              > {
              > short p = 4;
              >
              > Garda(p);
              > }
              >
              >
              > void Garda(short frog)
              > {
              > frog = 5;
              > }[/color]

              Yes, it should. Both declarations of 'Garda' "[...] agree exactly both
              in the type of the value returned and in the number and type of
              parameters [...]" (8.3.5/3). Additionally, note in 13.1/3 says that
              "[...] function declarations that have equivalent parameter declarations
              declare the same function [...]".

              --
              Best regards,
              Andrey Tarasevich

              Comment

              Working...