printf("%d", INT_MAX);

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

    #16
    Re: printf("%d ", INT_MAX);

    CBFalconer wrote, On 15/03/07 21:52:
    Eric Sosman wrote:
    ... snip ...
    > The distinction between strictly conforming and conforming
    >programs is one that the Standard is pretty much forced to make,
    >but it has always seemed to me that the Standard's definition
    >of strict conformance is too restrictive to be as useful as it
    >should be. When a program like Kenneth Brody's turns out not
    >to be strictly conforming, I think the baby has been thrown out
    >with the bath water. But I have no better definition to offer,
    >so I can't complain very convincingly!
    >
    I don't think a strictly conforming *program* exists,
    <pedantic>
    What about:
    int main(void)
    {
    return 0;
    }
    </pedantic>
    but many
    strictly conforming *routines* do exist. I.E. those routines that
    can be implemented anywhere.
    I think we can deal with code that is not strictly conforming within
    certain limits. Such as, to take a simple example, a program printing
    values from limits.h
    --
    Flash Gordon

    Comment

    • Eric Sosman

      #17
      Re: printf(&quot;%d &quot;, INT_MAX);

      Flash Gordon wrote On 03/16/07 14:48,:
      CBFalconer wrote, On 15/03/07 21:52:
      >
      >>Eric Sosman wrote:
      >>... snip ...
      >>
      >> The distinction between strictly conforming and conforming
      >>>programs is one that the Standard is pretty much forced to make,
      >>>but it has always seemed to me that the Standard's definition
      >>>of strict conformance is too restrictive to be as useful as it
      >>>should be. When a program like Kenneth Brody's turns out not
      >>>to be strictly conforming, I think the baby has been thrown out
      >>>with the bath water. But I have no better definition to offer,
      >>>so I can't complain very convincingly!
      >>
      >>I don't think a strictly conforming *program* exists,
      >
      >
      <pedantic>
      What about:
      int main(void)
      {
      return 0;
      }
      </pedantic>
      Sorry: It returns an implementation-defined form of
      "success" to the host environment. Something that goes
      from the program to the environment is surely "output,"
      hence the program produces implementation-defined output.

      ;-)
      I think we can deal with code that is not strictly conforming within
      certain limits. Such as, to take a simple example, a program printing
      values from limits.h
      Nailing down the "certain limits" is the hard part,
      the part for which I at least have nothing constructive
      to offer.

      "I shall not today attempt further to define the
      kinds of material I understand to be embraced
      within that shorthand description; and perhaps I
      could never succeed in intelligibly doing so. But
      I know it when I see it, [...]"
      -- Justice Potter Stewart

      --
      Eric.Sosman@sun .com

      Comment

      • CBFalconer

        #18
        Re: printf(&quot;%d &quot;, INT_MAX);

        Keith Thompson wrote:
        CBFalconer <cbfalconer@yah oo.comwrites:
        >
        .... snip ...
        >>
        >I don't think a strictly conforming *program* exists, but many
        >strictly conforming *routines* do exist. I.E. those routines that
        >can be implemented anywhere.
        >
        The standard doesn't talk about strictly conforming routines, and I
        think the phrase "strictly conforming" is so narrowly defined that
        we should avoid using it other than in the sense specified in the
        standard. The idea of "routines that can be implemented anywhere"
        is certainly a useful one, though; perhaps that's the same as
        "routines (function?) that can potentially be used in a strictly
        conforming program".
        For many years I have made a practice of trying to isolate routines
        that operate only on memory from something that affects
        peripherals, in any language. For example, I may have a routine
        that outputs a char, and one that converts a nibble to hex, I
        would break this up (in assembly) to:

        push acc
        shr 4
        call hexcvt
        call cout
        pop acc
        call hexcvt
        call cout

        and use of 'fallthru' can shorted the overall code. This might
        give me couthx as:

        couthx: call hexcvt
        ; " " (fall thru)
        cout: whatever

        reducing the above to:

        push acc
        shr 4
        call couthx
        pop acc
        ; " " (fall thru)
        couthx:

        You can't apply the fall thru strategies in C, but the rest
        applies.

        --
        Chuck F (cbfalconer at maineline dot net)
        Available for consulting/temporary embedded and systems.
        <http://cbfalconer.home .att.net>



        --
        Posted via a free Usenet account from http://www.teranews.com

        Comment

        • Keith Thompson

          #19
          Re: printf(&quot;%d &quot;, INT_MAX);

          Eric Sosman <Eric.Sosman@su n.comwrites:
          Flash Gordon wrote On 03/16/07 14:48,:
          >CBFalconer wrote, On 15/03/07 21:52:
          [...]
          >>>I don't think a strictly conforming *program* exists,
          >>
          >>
          ><pedantic>
          >What about:
          >int main(void)
          >{
          > return 0;
          >}
          ></pedantic>
          >
          Sorry: It returns an implementation-defined form of
          "success" to the host environment. Something that goes
          from the program to the environment is surely "output,"
          hence the program produces implementation-defined output.
          >
          ;-)
          I feel reasonably confident that the comittee did not intend the
          concept of "strictly conforming" to be quite *that* useless.

          However:

          int main(void) { while (1); }

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

          Comment

          • Flash Gordon

            #20
            Re: printf(&quot;%d &quot;, INT_MAX);

            Keith Thompson wrote, On 16/03/07 21:50:
            Eric Sosman <Eric.Sosman@su n.comwrites:
            >Flash Gordon wrote On 03/16/07 14:48,:
            >>CBFalconer wrote, On 15/03/07 21:52:
            [...]
            >>>I don't think a strictly conforming *program* exists,
            >>>
            >><pedantic>
            >>What about:
            >>int main(void)
            >>{
            >> return 0;
            >>}
            >></pedantic>
            > Sorry: It returns an implementation-defined form of
            >"success" to the host environment. Something that goes
            >from the program to the environment is surely "output,"
            >hence the program produces implementation-defined output.
            >>
            > ;-)
            >
            I feel reasonably confident that the comittee did not intend the
            concept of "strictly conforming" to be quite *that* useless.
            >
            However:
            >
            int main(void) { while (1); }
            It even still leaves us something to discuss. I prefer
            int main(void)
            {
            for (;;)
            continue;
            }

            :-)
            --
            Flash Gordon

            Comment

            • CBFalconer

              #21
              Re: printf(&quot;%d &quot;, INT_MAX);

              Flash Gordon wrote:
              >
              Keith Thompson wrote, On 16/03/07 21:50:
              >
              .... snip ...
              >
              >I feel reasonably confident that the comittee did not intend the
              >concept of "strictly conforming" to be quite *that* useless.
              >>
              >However:
              >>
              >int main(void) { while (1); }
              >
              It even still leaves us something to discuss. I prefer
              int main(void)
              {
              for (;;)
              continue;
              }
              You both omitted the final "return 0" for C90. :-)

              --
              Chuck F (cbfalconer at maineline dot net)
              Available for consulting/temporary embedded and systems.
              <http://cbfalconer.home .att.net>



              --
              Posted via a free Usenet account from http://www.teranews.com

              Comment

              • Keith Thompson

                #22
                Re: printf(&quot;%d &quot;, INT_MAX);

                CBFalconer <cbfalconer@yah oo.comwrites:
                Flash Gordon wrote:
                >Keith Thompson wrote, On 16/03/07 21:50:
                >>
                ... snip ...
                >>
                >>I feel reasonably confident that the comittee did not intend the
                >>concept of "strictly conforming" to be quite *that* useless.
                >>>
                >>However:
                >>>
                >>int main(void) { while (1); }
                >>
                >It even still leaves us something to discuss. I prefer
                >int main(void)
                >{
                > for (;;)
                > continue;
                >}
                >
                You both omitted the final "return 0" for C90. :-)
                Which could cause problems as soon as control reaches the closing
                brace. Wait here and let me know what happens.

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

                Comment

                • Eric Sosman

                  #23
                  Re: printf(&quot;%d &quot;, INT_MAX);

                  Keith Thompson wrote On 03/16/07 17:50,:
                  Eric Sosman <Eric.Sosman@su n.comwrites:
                  >
                  >>Flash Gordon wrote On 03/16/07 14:48,:
                  >>
                  >>>CBFalconer wrote, On 15/03/07 21:52:
                  >
                  [...]
                  >
                  >>>>I don't think a strictly conforming *program* exists,
                  >>>
                  >>>
                  >>><pedantic>
                  >>>What about:
                  >>>int main(void)
                  >>>{
                  >> return 0;
                  >>>}
                  >>></pedantic>
                  >>
                  > Sorry: It returns an implementation-defined form of
                  >>"success" to the host environment. Something that goes
                  >>from the program to the environment is surely "output,"
                  >>hence the program produces implementation-defined output.
                  >>
                  > ;-)
                  >
                  >
                  I feel reasonably confident that the comittee did not intend the
                  concept of "strictly conforming" to be quite *that* useless.
                  >
                  However:
                  >
                  int main(void) { while (1); }
                  Strictly conforming, I believe. The problem is to find
                  an implementation that can execute it correctly.

                  --
                  Eric.Sosman@sun .com

                  Comment

                  • pete

                    #24
                    Re: printf(&quot;%d &quot;, INT_MAX);

                    Eric Sosman wrote:
                    >
                    Keith Thompson wrote On 03/16/07 17:50,:
                    int main(void) { while (1); }
                    >
                    Strictly conforming, I believe. The problem is to find
                    an implementation that can execute it correctly.
                    Here's another one that's strictly conforming
                    and which some M$ compilers won't compile:

                    int main(void)
                    {
                    int zero = 0;

                    return zero && (1 / 0);
                    }

                    --
                    pete

                    Comment

                    • =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=

                      #25
                      Re: printf(&quot;%d &quot;, INT_MAX);

                      pete wrote:
                      Eric Sosman wrote:

                      Keith Thompson wrote On 03/16/07 17:50,:
                      >
                      int main(void) { while (1); }
                      Strictly conforming, I believe. The problem is to find
                      an implementation that can execute it correctly.
                      >
                      Here's another one that's strictly conforming
                      and which some M$ compilers won't compile:
                      >
                      int main(void)
                      {
                      int zero = 0;
                      >
                      return zero && (1 / 0);
                      }
                      Here's another one that's strictly conforming and which some G¢¢
                      (seriously, enough with the "M$") compilers won't compile:

                      int f(void)
                      {
                      int result = 1 / 0;
                      return result;
                      }

                      int main(void)
                      {
                      return 0 && f();
                      }

                      Comment

                      • Joe Wright

                        #26
                        Re: printf(&quot;%d &quot;, INT_MAX);

                        Harald van Dijk wrote:
                        pete wrote:
                        >Eric Sosman wrote:
                        >>Keith Thompson wrote On 03/16/07 17:50,:
                        >>>int main(void) { while (1); }
                        >> Strictly conforming, I believe. The problem is to find
                        >>an implementation that can execute it correctly.
                        >Here's another one that's strictly conforming
                        >and which some M$ compilers won't compile:
                        >>
                        >int main(void)
                        >{
                        > int zero = 0;
                        >>
                        > return zero && (1 / 0);
                        >}
                        >
                        Here's another one that's strictly conforming and which some G¢¢
                        (seriously, enough with the "M$") compilers won't compile:
                        >
                        int f(void)
                        {
                        int result = 1 / 0;
                        return result;
                        }
                        >
                        int main(void)
                        {
                        return 0 && f();
                        }
                        >
                        My DJGPP (GNU C 3.1) issues a warning..

                        d0.c: In function `f':
                        d0.c:3: warning: division by zero

                        ...and compiles. Running the program gives no error so I'll assume f()
                        doesn't get called.

                        --
                        Joe Wright
                        "Everything should be made as simple as possible, but not simpler."
                        --- Albert Einstein ---

                        Comment

                        • =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=

                          #27
                          Re: printf(&quot;%d &quot;, INT_MAX);

                          Joe Wright wrote:
                          Harald van Dijk wrote:
                          pete wrote:
                          Eric Sosman wrote:
                          >Keith Thompson wrote On 03/16/07 17:50,:
                          >>int main(void) { while (1); }
                          > Strictly conforming, I believe. The problem is to find
                          >an implementation that can execute it correctly.
                          Here's another one that's strictly conforming
                          and which some M$ compilers won't compile:
                          >
                          int main(void)
                          {
                          int zero = 0;
                          >
                          return zero && (1 / 0);
                          }
                          Here's another one that's strictly conforming and which some G¢¢
                          (seriously, enough with the "M$") compilers won't compile:

                          int f(void)
                          {
                          int result = 1 / 0;
                          return result;
                          }

                          int main(void)
                          {
                          return 0 && f();
                          }
                          My DJGPP (GNU C 3.1) issues a warning..
                          >
                          d0.c: In function `f':
                          d0.c:3: warning: division by zero
                          >
                          ..and compiles. Running the program gives no error so I'll assume f()
                          doesn't get called.
                          Try compiling with the -ansi and -pedantic-errors options (with which
                          GCC aims to conform to C90 as strictly as allowed). If it still works
                          then, you're not using a version of GCC affected by that particular
                          bug.

                          Comment

                          Working...