is order urgent doubt

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

    is order urgent doubt

    Hi!

    I write the 2 codes

    int i;
    i = sizeof(long int);
    printf("%i", i);

    i = sizeof(int long);
    printf("%i", i);

    and the first code and second code print 4.

    I write another 2 codes

    i = sizeof(double int);
    printf("%i", i);

    i = sizeof(int double);
    printf("%i", i);

    and the first code print 4 and the second code print 8.

    My doubt is why is different number? Is order urgent?

  • Eric Sosman

    #2
    Re: is order urgent doubt

    new to c wrote:
    Hi!
    >
    I write the 2 codes
    >
    int i;
    i = sizeof(long int);
    printf("%i", i);
    >
    i = sizeof(int long);
    printf("%i", i);
    >
    and the first code and second code print 4.
    >
    I write another 2 codes
    >
    i = sizeof(double int);
    printf("%i", i);
    >
    i = sizeof(int double);
    printf("%i", i);
    >
    and the first code print 4 and the second code print 8.
    I'm surprised you got any output at all, because neither
    `double int' nor `int double' is a valid type name. You
    should have received error messages from the compiler.
    My doubt is why is different number? Is order urgent?
    Not in C, but your compiler seems to be processing some
    other language.

    --
    Eric Sosman
    esosman@ieee-dot-org.invalid

    Comment

    • Keith Thompson

      #3
      Re: is order urgent doubt

      new to c <non@spam.inval idwrites:
      I write the 2 codes
      >
      int i;
      i = sizeof(long int);
      printf("%i", i);
      >
      i = sizeof(int long);
      printf("%i", i);
      >
      and the first code and second code print 4.
      Right. It won't necessarily be 4 on all systems, but both are
      equivalent.

      However, "int long" is very non-idiomatic. The compiler can handle it
      with no problem, but human readers are going to stumble over it.

      (Please ignore the long flame war that will now begin claiming that
      anyone who knows C should be able to read "int long" without any
      trouble. The fact that the C standard allows variations in the order
      of the keywords is fairly obscure; a member of the standard committee
      recently posted here saying he didn't even know about it.)
      I write another 2 codes
      >
      i = sizeof(double int);
      printf("%i", i);
      >
      i = sizeof(int double);
      printf("%i", i);
      >
      and the first code print 4 and the second code print 8.
      That's surprising. Your compiler should have rejected it, or at least
      warned you about it. Are you sure that's *exactly* what you wrote?

      [...]

      --
      Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
      Nokia
      "We must do something. This is something. Therefore, we must do this."
      -- Antony Jay and Jonathan Lynn, "Yes Minister"

      Comment

      • Richard Heathfield

        #4
        Re: is order urgent doubt

        Keith Thompson said:

        <snip>
        (Please ignore the long flame war that will now begin claiming that
        anyone who knows C should be able to read "int long" without any
        trouble.
        Well, really, Keith, they *should*. I suppose I differ from the "char
        unsigned" camp in that I think that writing "char unsigned" rather than
        "unsigned char" is bone-headedly dense and ludicrously unfriendly, but
        that doesn't give C programmers an excuse not to know that it's possible -
        or at least not to be able to find out quickly that it's possible and
        legal, the first time they encounter it, which is admittedly "never" for
        most C programmers.
        The fact that the C standard allows variations in the order
        of the keywords is fairly obscure; a member of the standard committee
        recently posted here saying he didn't even know about it.)
        I think that says more about the member than it does about the language.

        <snip>

        --
        Richard Heathfield <http://www.cpax.org.uk >
        Email: -http://www. +rjh@
        Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
        "Usenet is a strange place" - dmr 29 July 1999

        Comment

        • teapot

          #5
          Re: is order urgent doubt

          Eric Sosman wrote:
          >new to c wrote:
          >Hi!
          >>
          >I write the 2 codes
          >>
          >int i;
          >i = sizeof(long int);
          >printf("%i", i);
          >>
          >i = sizeof(int long);
          >printf("%i", i);
          >>
          >and the first code and second code print 4.
          >>
          >I write another 2 codes
          >>
          >i = sizeof(double int);
          >printf("%i", i);
          >>
          >i = sizeof(int double);
          >printf("%i", i);
          >>
          >and the first code print 4 and the second code print 8.
          >
          I'm surprised you got any output at all, because neither
          >`double int' nor `int double' is a valid type name. You
          >should have received error messages from the compiler.
          >
          >My doubt is why is different number? Is order urgent?
          >
          Not in C, but your compiler seems to be processing some
          >other language.
          It appears to be pseudo legal in <unnamed compiler>.

          In case OP is using said compiler, here are some quick observations --

          (1) if `signed' and `unsigned' appear in the same declaration, only
          the last one specified affects signedness.

          [Based on earlier observations, <unnamed compileraccepts
          `signed main()' but rejects `unsigned main()'. Tests show that
          `unsigned signed main()' is accepted but `signed unsigned main()'
          is not, from that we can conclude that later modifiers affecting
          signedness probably overrule earlier ones.]


          (2) if more than one base type appears in a declaration, sometimes,
          later conflicting types overrule earlier ones.

          [The test method here uses the fact that doing something illegal
          (assignment to object of incompatible type) produces a diagnostic
          that reveals the actual type of the created object. Consider this
          code snippet

          void *foo;
          double int bar; /* line 5 */
          int double baz; /* line 6 */
          foo = bar; /* line 7 */
          foo = baz; /* line 8 */

          5: W: multiple use of 'int'
          6: W: multiple use of 'double'
          7: E: operands of = have illegal types 'pointer to void' and 'int'
          8: E: operands of = have illegal types 'pointer to void' and 'double'

          From that we can conclude that `bar' probably has type `int' and
          `baz' probaby has type `double'.

          Using the same procedure it turns out that `long long double' is
          seen as plain `double', but `long double int' is `long int'.
          `long short' is `short' and `short long' is `long', `long short long'
          is `long' and `short long short' is `short' -- the same rules
          affecting signedness discovered in (1) probably also apply when
          deciding short or longness.

          There is, however, a small inconsistency in that `short short short'
          is probably `short' but `long long long' is in category (3)]


          (3) other combinations are flagged as errors and compilation stops --

          [Same method used as before

          void *foo;
          unsigned double bar; /* line 5 */
          double unsigned baz; /* line 6 */
          foo = bar; /* line 7 */
          foo = baz; /* line 8 */

          5: E: invalid type specification
          6: E: invalid type specification


          In conclusion, <unnamed compilertreats some illegal combinations
          of types/types and types/modifiers as errors, others merely as
          warnings; but they are warned about even without any flags
          requesting extra warnings and <unnamed compilerappears to be
          conforming in these regards.

          Answering the original question, `double int' is not a valid
          type, but some implementations , in certain cases, appear to pick
          one type if more than one is given. In <unnamed compiler>,

          `double int' is seen as `int',

          and

          `int double' is seen as `double',

          in both cases after issuing the required diagnostic (warning).

          --
          T.Pot.

          Comment

          • new to c

            #6
            Re: is order urgent doubt

            Keith Thompson wrote:
            new to c <non@spam.inval idwrites:
            >I write the 2 codes
            >>
            >int i;
            >i = sizeof(long int);
            >printf("%i", i);
            >>
            >i = sizeof(int long);
            >printf("%i", i);
            >>
            >and the first code and second code print 4.
            >
            Right. It won't necessarily be 4 on all systems, but both are
            equivalent.
            >
            However, "int long" is very non-idiomatic. The compiler can handle it
            with no problem, but human readers are going to stumble over it.
            >
            (Please ignore the long flame war that will now begin claiming that
            anyone who knows C should be able to read "int long" without any
            trouble. The fact that the C standard allows variations in the order
            of the keywords is fairly obscure; a member of the standard committee
            recently posted here saying he didn't even know about it.)
            >
            >I write another 2 codes
            >>
            >i = sizeof(double int);
            >printf("%i", i);
            >>
            >i = sizeof(int double);
            >printf("%i", i);
            >>
            >and the first code print 4 and the second code print 8.
            >
            That's surprising. Your compiler should have rejected it, or at least
            warned you about it. Are you sure that's *exactly* what you wrote?
            >
            He warn "multiple use of int" on first code and "multiple use of double"
            on second code but I think is bogus......only one int in first code and
            only one double in second code.

            I write big international program and need double integer. Why size is
            different when other order?

            Comment

            • Eric Sosman

              #7
              Re: is order urgent doubt

              new to c wrote:
              Keith Thompson wrote:
              >
              >new to c <non@spam.inval idwrites:
              >>[...]
              >>I write another 2 codes
              >>>
              >>i = sizeof(double int);
              >>printf("%i" , i);
              >>>
              >>i = sizeof(int double);
              >>printf("%i" , i);
              >>>
              >>and the first code print 4 and the second code print 8.
              >That's surprising. Your compiler should have rejected it, or at least
              >warned you about it. Are you sure that's *exactly* what you wrote?
              >>
              >
              He warn "multiple use of int" on first code and "multiple use of double"
              on second code but I think is bogus......only one int in first code and
              only one double in second code.
              The wording of the diagnostic message may be misleading,
              but that's something you should learn to expect when dealing
              with computers. You should start by reading the message and
              trying to understand its complaint. If it seems to make no
              sense, re-interpret it as meaning "Something is wrong here, but
              I can't describe it." If even that seems to make no sense,
              read it as "Something is wrong somewhere, maybe not close to
              the spot the message complains about."
              I write big international program and need double integer. Why size is
              different when other order?
              There is no such thing as a `double int' or `int double'
              in C. Why do you believe you need a "double integer," that
              is, what do you hope a "double integer" variable will do
              for your program? What are the characteristics of the "double
              integer" you think you need? Perhaps there is some actual C
              type that will suit your purpose.

              --
              Eric Sosman
              esosman@ieee-dot-org.invalid

              Comment

              • Bartc

                #8
                Re: is order urgent doubt


                "new to c" <non@spam.inval idwrote in message
                news:6468955.gy paU67uLZ@news.a ioe.org...

                I write big international program and need double integer. Why size is
                different when other order?
                Try: long long int

                If you're lucky, this will have size 8.

                In C, 'double' is just a bigger version of 'float'

                --
                Bartc


                Comment

                Working...