Some simple questions

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

    Some simple questions

    1. 1U means that 1 is an unsigned int and not another unsigned type?

    2. '\012' and '\xb' values are the same with 012 and 0xb?

    3. Any numbers appearing like the following:

    '\546'

    are considered octals or decimals?
  • Juha Nieminen

    #2
    Re: Some simple questions

    Ioannis Vranos wrote:
    1. 1U means that 1 is an unsigned int and not another unsigned type?
    Unsigned int.
    2. '\012' and '\xb' values are the same with 012 and 0xb?
    No. The former are of type char, while the latter are of type int.
    3. Any numbers appearing like the following:
    >
    '\546'
    >
    are considered octals or decimals?
    I don't remember. Try google.

    Comment

    • Ioannis Vranos

      #3
      Re: Some simple questions

      Juha Nieminen wrote:
      Ioannis Vranos wrote:
      >1. 1U means that 1 is an unsigned int and not another unsigned type?
      >
      Unsigned int.
      Is there any specifier of unsigned short?

      >
      >2. '\012' and '\xb' values are the same with 012 and 0xb?
      >
      No. The former are of type char, while the latter are of type int.

      OK, apart from the type, are these the same values?

      >
      >3. Any numbers appearing like the following:
      >>
      >'\546'
      >>
      >are considered octals or decimals?
      >
      I don't remember. Try google.
      If anyone has a specific answer it will be better. As for trying, a
      compiler is better than google for this case I guess. :-)

      Comment

      • Ioannis Vranos

        #4
        Re: Some simple questions

        Ioannis Vranos wrote:
        Juha Nieminen wrote:
        >Ioannis Vranos wrote:
        >>1. 1U means that 1 is an unsigned int and not another unsigned type?
        >>
        > Unsigned int.
        >
        Is there any specifier of unsigned short?
        >
        >
        >>
        >>2. '\012' and '\xb' values are the same with 012 and 0xb?
        >>
        > No. The former are of type char, while the latter are of type int.
        >
        >
        OK, apart from the type, are these the same values?
        >
        >
        >>
        >>3. Any numbers appearing like the following:
        >>>
        >>'\546'
        >>>
        >>are considered octals or decimals?
        >>
        > I don't remember. Try google.
        >
        If anyone has a specific answer it will be better. As for trying, a
        compiler is better than google for this case I guess. :-)

        The code:

        #include <iostream>


        int main()
        {
        using namespace std;

        int x= '\146';


        cout<< x<< "\n"<< oct<< x<< "\n"<< hex<< x<< endl;
        }


        produces in my system:


        [john@localhost src]$ ./foobar-cpp
        102
        146
        66
        [john@localhost src]$


        Can't reach a conclusion.

        Comment

        • Ioannis Vranos

          #5
          Re: Some simple questions

          Ioannis Vranos wrote:
          Ioannis Vranos wrote:
          >Juha Nieminen wrote:
          >>Ioannis Vranos wrote:
          >>>1. 1U means that 1 is an unsigned int and not another unsigned type?
          >>>
          >> Unsigned int.
          >>
          >Is there any specifier of unsigned short?
          >>
          >>
          >>>
          >>>2. '\012' and '\xb' values are the same with 012 and 0xb?
          >>>
          >> No. The former are of type char, while the latter are of type int.
          >>
          >>
          >OK, apart from the type, are these the same values?
          >>
          >>
          >>>
          >>>3. Any numbers appearing like the following:
          >>>>
          >>>'\546'
          >>>>
          >>>are considered octals or decimals?
          >>>
          >> I don't remember. Try google.
          >>
          >If anyone has a specific answer it will be better. As for trying, a
          >compiler is better than google for this case I guess. :-)
          >
          >
          The code:
          >
          #include <iostream>
          >
          >
          int main()
          {
          using namespace std;
          >
          int x= '\146';
          >
          >
          cout<< x<< "\n"<< oct<< x<< "\n"<< hex<< x<< endl;
          }
          >
          >
          produces in my system:
          >
          >
          [john@localhost src]$ ./foobar-cpp
          102
          146
          66
          [john@localhost src]$
          >
          >
          Can't reach a conclusion.

          Ehm, actually it looks like it is octal.

          Comment

          • James Kanze

            #6
            Re: Some simple questions

            On Feb 29, 6:24 pm, Ioannis Vranos <ivra...@nospam .no.spamfreemai l.gr>
            wrote:
            1. 1U means that 1 is an unsigned int and not another unsigned type?
            Yes, but only because 1 is guaranteed to fit in an int. If
            integer literal which is suffixed by u or U, "its type is the
            first of these types in which its value can be represented:
            unsigned int, unsigned long int." C++0x will add long long, and
            provisions for extended integral types (but U or u will always
            guarantee an unsigned type, I think).
            2. '\012' and '\xb' values are the same with 012 and 0xb?
            No. The first two have type char, the last two type int. (They
            have the same numeric value of course, but I'm sure you knew
            that.)
            3. Any numbers appearing like the following:
            '\546'
            are considered octals or decimals?
            Octals. Character escape sequences only exist for octal and
            hexadecimal, not for decimal. (Similarly, the length and
            precision fields in a printf format specifier are always
            decimal, regardless of the format; e.g. "%.017f" and "%.17f"
            specify exactly the same format, and in "%010d", the initial 0
            is a flag, saying to use 0 as a fill character, and not space,
            and does not mean that the width is octal.)

            --
            James Kanze (GABI Software) email:james.kan ze@gmail.com
            Conseils en informatique orientée objet/
            Beratung in objektorientier ter Datenverarbeitu ng
            9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

            Comment

            • James Kanze

              #7
              Re: Some simple questions

              On Feb 29, 7:45 pm, Ioannis Vranos <ivra...@nospam .no.spamfreemai l.gr>
              wrote:
              Juha Nieminen wrote:
              Ioannis Vranos wrote:
              1. 1U means that 1 is an unsigned int and not another unsigned type?
              Unsigned int.
              Is there any specifier of unsigned short?
              No. Integral promotion means that shorts and unsigned shorts
              don't usually occur in expressions.

              --
              James Kanze (GABI Software) email:james.kan ze@gmail.com
              Conseils en informatique orientée objet/
              Beratung in objektorientier ter Datenverarbeitu ng
              9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

              Comment

              • Ioannis Vranos

                #8
                Re: Some simple questions

                James Kanze wrote:
                On Feb 29, 6:24 pm, Ioannis Vranos <ivra...@nospam .no.spamfreemai l.gr>
                wrote:
                >1. 1U means that 1 is an unsigned int and not another unsigned type?
                >
                Yes, but only because 1 is guaranteed to fit in an int. If
                integer literal which is suffixed by u or U, "its type is the
                first of these types in which its value can be represented:
                unsigned int, unsigned long int."

                Thanks for the info.

                C++0x will add long long, and
                provisions for extended integral types (but U or u will always
                guarantee an unsigned type, I think).

                I will bother for C++0x when it is ratified and is widely implemented,
                that is about 4 years after it is finished at least. :-)

                >2. '\012' and '\xb' values are the same with 012 and 0xb?
                >
                No. The first two have type char, the last two type int. (They
                have the same numeric value of course, but I'm sure you knew
                that.)

                Actually I knew the first but was not sure for the second. :-)


                >3. Any numbers appearing like the following:
                >
                >'\546'
                >
                >are considered octals or decimals?
                >
                Octals. Character escape sequences only exist for octal and
                hexadecimal, not for decimal.

                I suppose you mean numeric escape sequences, and not talking about '\n',
                '\t' etc.

                Comment

                • James Kanze

                  #9
                  Re: Some simple questions

                  On Feb 29, 9:10 pm, Ioannis Vranos <ivra...@nospam .no.spamfreemai l.gr>
                  wrote:
                  James Kanze wrote:
                  [...]
                  C++0x will add long long, and
                  provisions for extended integral types (but U or u will always
                  guarantee an unsigned type, I think).
                  I will bother for C++0x when it is ratified and is widely
                  implemented, that is about 4 years after it is finished at
                  least. :-)
                  Were it only so. In practice, some features are already widely
                  implemented (such as long long), others probably never will be
                  (how many compilers support export, from C++98).

                  [...]
                  3. Any numbers appearing like the following:
                  '\546'
                  are considered octals or decimals?
                  >
                  Octals. Character escape sequences only exist for octal and
                  hexadecimal, not for decimal.
                  I suppose you mean numeric escape sequences, and not talking
                  about '\n', '\t' etc.
                  Yes. Things like '\t' are neither octal nor decimal, of course.

                  --
                  James Kanze (GABI Software) email:james.kan ze@gmail.com
                  Conseils en informatique orientée objet/
                  Beratung in objektorientier ter Datenverarbeitu ng
                  9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                  Comment

                  • Micah Cowan

                    #10
                    Re: Some simple questions

                    Juha Nieminen <nospam@thanks. invalidwrites:
                    Ioannis Vranos wrote:
                    >1. 1U means that 1 is an unsigned int and not another unsigned type?
                    >
                    Unsigned int.
                    >
                    >2. '\012' and '\xb' values are the same with 012 and 0xb?
                    >
                    No. The former are of type char, while the latter are of type int.
                    (Note that this differs from C, where all of the above are of type
                    int.)

                    --
                    Micah J. Cowan
                    Programmer, musician, typesetting enthusiast, gamer...

                    Comment

                    • Juha Nieminen

                      #11
                      Re: Some simple questions

                      Micah Cowan wrote:
                      Juha Nieminen <nospam@thanks. invalidwrites:
                      >
                      >Ioannis Vranos wrote:
                      >>1. 1U means that 1 is an unsigned int and not another unsigned type?
                      > Unsigned int.
                      >>
                      >>2. '\012' and '\xb' values are the same with 012 and 0xb?
                      > No. The former are of type char, while the latter are of type int.
                      >
                      (Note that this differs from C, where all of the above are of type
                      int.)
                      Even 1U is of type int?

                      Comment

                      • Victor Bazarov

                        #12
                        Re: Some simple questions

                        Juha Nieminen wrote:
                        Micah Cowan wrote:
                        >Juha Nieminen <nospam@thanks. invalidwrites:
                        >>
                        >>Ioannis Vranos wrote:
                        >>>1. 1U means that 1 is an unsigned int and not another unsigned
                        >>>type?
                        >> Unsigned int.
                        >>>
                        >>>2. '\012' and '\xb' values are the same with 012 and 0xb?
                        >> No. The former are of type char, while the latter are of type int.
                        >>
                        >(Note that this differs from C, where all of the above are of type
                        >int.)
                        >
                        Even 1U is of type int?
                        No, Micah meant all literals in '2' are of type 'int' in C. There
                        are no literals of type 'char' in C.

                        V
                        --
                        Please remove capital 'A's when replying by e-mail
                        I do not respond to top-posted replies, please don't ask


                        Comment

                        • Juha Nieminen

                          #13
                          Re: Some simple questions

                          Victor Bazarov wrote:
                          Juha Nieminen wrote:
                          >Micah Cowan wrote:
                          >>Juha Nieminen <nospam@thanks. invalidwrites:
                          >>>
                          >>>Ioannis Vranos wrote:
                          >>>>1. 1U means that 1 is an unsigned int and not another unsigned
                          >>>>type?
                          >>> Unsigned int.
                          >>>>
                          >>>>2. '\012' and '\xb' values are the same with 012 and 0xb?
                          >>> No. The former are of type char, while the latter are of type int.
                          >>(Note that this differs from C, where all of the above are of type
                          >>int.)
                          > Even 1U is of type int?
                          >
                          No, Micah meant all literals in '2' are of type 'int' in C. There
                          are no literals of type 'char' in C.
                          My answer was a rather subtle hint which tried to say "please quote
                          only the relevant parts of what you are answering to, to avoid confusion".

                          Comment

                          • Victor Bazarov

                            #14
                            Re: Some simple questions

                            Juha Nieminen wrote:
                            Victor Bazarov wrote:
                            >Juha Nieminen wrote:
                            >>Micah Cowan wrote:
                            >>>Juha Nieminen <nospam@thanks. invalidwrites:
                            >>>>
                            >>>>Ioannis Vranos wrote:
                            >>>>>1. 1U means that 1 is an unsigned int and not another unsigned
                            >>>>>type?
                            >>>> Unsigned int.
                            >>>>>
                            >>>>>2. '\012' and '\xb' values are the same with 012 and 0xb?
                            >>>> No. The former are of type char, while the latter are of type
                            >>>>int.
                            >>>(Note that this differs from C, where all of the above are of type
                            >>>int.)
                            >> Even 1U is of type int?
                            >>
                            >No, Micah meant all literals in '2' are of type 'int' in C. There
                            >are no literals of type 'char' in C.
                            >
                            My answer was a rather subtle hint which tried to say "please quote
                            only the relevant parts of what you are answering to, to avoid
                            confusion".
                            'Twas too subtle for me, obviously.

                            V
                            --
                            Please remove capital 'A's when replying by e-mail
                            I do not respond to top-posted replies, please don't ask


                            Comment

                            Working...