problem with output of the program on different OS

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

    problem with output of the program on different OS

    I have a C program which I created on Windows machine. I have compiled
    and executed the program on windows machine and it gives me the
    consistent output every time i run it. for eg.

    input a = 2, b =3

    lets say a sum operation is to be performed, then:

    output: 5

    The output is always consistent and correct with regards to input.

    I tried to run the program on my linux machine. The program compiles
    and executes but I'm getting strange results. For eg. for the problem
    of addition above:

    input a = 2 b = 3

    output: 1

    i execute the program again:

    input a = 2 b = 3

    output: 6

    and again:

    input a = 2 b= 3

    output 0

    What is happening ?
  • Richard Heathfield

    #2
    Re: problem with output of the program on different OS

    pereges said:
    I have a C program which I created on Windows machine. [...]
    >
    The output is always consistent and correct with regards to input.
    >
    I tried to run the program on my linux machine. The program compiles
    and executes but I'm getting strange results. [...]
    >
    What is happening ?
    Classic case of undefined behaviour. For a more detailed diagnosis, please
    provide source code.

    --
    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

    • pereges

      #3
      Re: problem with output of the program on different OS

      On May 8, 1:26 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
      <snip>
      Classic case of undefined behaviour. For a more detailed diagnosis, please
      provide source code.
      >
      The code is 650 lines and it is divided in many modules. I don't mind
      posting it but most people will resent it.

      Do yout think problems like this one can arise by using non standard
      compilers like PellesC ?


      Comment

      • Ian Collins

        #4
        Re: problem with output of the program on different OS

        pereges wrote:
        On May 8, 1:26 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
        <snip>
        >Classic case of undefined behaviour. For a more detailed diagnosis, please
        >provide source code.
        >>
        >
        The code is 650 lines and it is divided in many modules. I don't mind
        posting it but most people will resent it.
        >
        Do yout think problems like this one can arise by using non standard
        compilers like PellesC ?
        >
        More likely undefined behaviour in the code that relies on the
        behaviour of the original compiler.

        Try and distill a short example that demonstrates the problem.

        --
        Ian Collins.

        Comment

        • pereges

          #5
          Re: problem with output of the program on different OS

          On May 8, 1:42 pm, Ian Collins <ian-n...@hotmail.co mwrote:
          Do yout think problems like this one can arise by using non standard
          compilers like PellesC ?
          >
          More likely undefined behaviour in the code that relies on the
          behaviour of the original compiler.
          >
          Try and distill a short example that demonstrates the problem.

          The original compiler I had used was Pelles C (to get a working
          output). I will try to post a small version of my code and describe
          where I think the problem lies.

          Comment

          • Richard Heathfield

            #6
            Re: problem with output of the program on different OS

            pereges said:
            On May 8, 1:26 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
            <snip>
            >Classic case of undefined behaviour. For a more detailed diagnosis,
            >please provide source code.
            >
            The code is 650 lines and it is divided in many modules. I don't mind
            posting it but most people will resent it.
            Zip up all the .c and .h files and any data required for reproducing the
            problem, stick it on the Web somewhere, and post a URL. That way, anyone
            who wants to look can do so, without inconveniencing anyone who doesn't
            want to.

            Don't include executable images or object files in the zip file; nobody
            will use them anyway, so they'd just be a waste of bandwidth.

            --
            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

            • Nick Keighley

              #7
              Re: problem with output of the program on different OS

              On 8 May, 09:20, pereges <Brol...@gmail. comwrote:
              I have a C program which I created on Windows machine. I have compiled
              and executed the program on windows machine and it gives me the
              consistent output every time i run it. for eg.
              >
              input a = 2, b =3
              >
              lets say a sum operation is to be performed, then:
              >
              output: 5
              >
              The output is always consistent and correct with regards to input.
              >
              I tried to run the program on my linux machine. The program compiles
              and executes but I'm getting strange results. For eg. for the problem
              of addition above:
              >
              input a = 2 b = 3
              >
              output: 1
              >
              i execute the program again:
              >
              input a = 2 b = 3
              >
              output: 6
              >
              and again:
              >
              input a = 2 b= 3
              >
              output 0
              >
              What is happening ?
              there is an instance of Undefined Behaviour on line 42

              --
              Nick Keighley

              Comment

              • jacob navia

                #8
                Re: problem with output of the program on different OS

                pereges wrote:
                On May 8, 1:26 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
                <snip>
                >Classic case of undefined behaviour. For a more detailed diagnosis, please
                >provide source code.
                >>
                >
                The code is 650 lines and it is divided in many modules. I don't mind
                posting it but most people will resent it.
                >
                Do yout think problems like this one can arise by using non standard
                compilers like PellesC ?
                >
                >
                Pelles C is a very standard compiler (ansic 89), and it is derived from
                lcc, that is very strictly conforming to C 89. Do not blame the compiler
                unless you are very sure of your code.


                --
                jacob navia
                jacob at jacob point remcomp point fr
                logiciels/informatique

                Comment

                • Bart

                  #9
                  Re: problem with output of the program on different OS

                  On May 8, 9:20 am, pereges <Brol...@gmail. comwrote:
                  I have a C program which I created on Windows machine. I have compiled
                  and executed the program on windows machine and it gives me the
                  consistent output every time i run it. for eg.
                  >
                  input a = 2, b =3
                  >
                  lets say a sum operation is to be performed, then:
                  >
                  output: 5
                  >
                  The output is always consistent and correct with regards to input.
                  >
                  I tried to run the program on my linux machine. The program compiles
                  and executes but I'm getting strange results. For eg. for the problem
                  of addition above:
                  >
                  input a = 2 b = 3
                  >
                  output: 1
                  >
                  i execute the program again:
                  >
                  input a = 2 b = 3
                  >
                  output: 6
                  >
                  and again:
                  >
                  input a = 2 b= 3
                  >
                  output 0
                  >
                  What is happening ?
                  Well, you can forget about the Windows version and just try some
                  debugging! Your program clearly isn't producing the output you expect.

                  Or, to save some work, compile with something like gcc with every
                  possible warning. Perhaps like:

                  gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align -
                  Wpointer-arith -Wbad-function-cast -Wmissing-prototypes -Wstrict-
                  prototypes -Wmissing-declarations -Winline -Wundef -Wnested-externs -
                  Wcast-qual -Wshadow -Wconversion -Wwrite-strings -ffloat-store -fno-
                  builtin -O2 -g -pg YOURPROG.c

                  (with thanks to R. Heathfield).

                  Then it might give some clues as to what might be wrong. Maybe some
                  array is too small; just double each one. It might help, or it might
                  also hide the real error.

                  650 lines isn't very big, why many modules? Sometimes separating into
                  modules can introduce more errors. Perhaps try temporarily combining
                  into one big file.

                  --
                  Bartc

                  Comment

                  • pereges

                    #10
                    Re: problem with output of the program on different OS

                    On May 8, 6:45 pm, Bart <b...@freeuk.co mwrote:
                    Well, you can forget about the Windows version and just try some
                    debugging! Your program clearly isn't producing the output you expect.
                    Can you please tell me about a good debugger ? Is there some
                    preliminary stuff I should read about debugging in C prior to using a
                    debugger ?

                    650 lines isn't very big, why many modules? Sometimes separating into
                    modules can introduce more errors. Perhaps try temporarily combining
                    into one big file.
                    well, I have a total of 9 modules in my program(countin g the .c and
                    the corresponding .h as 1 module).I was told to write the code in
                    sucha way that the individual modules can be reused in some other
                    programs.

                    Comment

                    • Richard Heathfield

                      #11
                      Re: problem with output of the program on different OS

                      pereges said:
                      On May 8, 6:45 pm, Bart <b...@freeuk.co mwrote:
                      >
                      >Well, you can forget about the Windows version and just try some
                      >debugging! Your program clearly isn't producing the output you expect.
                      >
                      Can you please tell me about a good debugger ? Is there some
                      preliminary stuff I should read about debugging in C prior to using a
                      debugger ?
                      Debuggers are over-rated by some people, and can be a huge time sink if
                      used flailingly.
                      >650 lines isn't very big, why many modules? Sometimes separating into
                      >modules can introduce more errors. Perhaps try temporarily combining
                      >into one big file.
                      >
                      well, I have a total of 9 modules in my program(countin g the .c and
                      the corresponding .h as 1 module).I was told to write the code in
                      sucha way that the individual modules can be reused in some other
                      programs.
                      Yes, I agree with you that the comment about design was misguided. Module
                      boundaries should be drawn to reflect differences in functionality. The
                      idea that you have some kind of Procrustean source bed, such that any file
                      longer than N lines must be split, is silly.

                      Is that zip file ready yet?

                      --
                      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

                      • pereges

                        #12
                        Re: problem with output of the program on different OS

                        On May 9, 10:52 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
                        Debuggers are over-rated by some people, and can be a huge time sink if
                        used flailingly.
                        Yes, I agree with you that the comment about design was misguided. Module
                        boundaries should be drawn to reflect differences in functionality. The
                        idea that you have some kind of Procrustean source bed, such that any file
                        longer than N lines must be split, is silly.
                        Is that zip file ready yet?


                        Can you please provide some general tips as to how I can improve my
                        style of coding ?

                        thanks

                        Comment

                        • Richard Heathfield

                          #13
                          Re: problem with output of the program on different OS

                          pereges said:
                          On May 9, 10:52 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
                          >
                          <snip>
                          >
                          >Is that zip file ready yet?
                          >
                          http://www.savefile.com/files/1547165
                          A somewhat cumbersome interface to a somewhat awkward RAR file. Not your
                          fault, of course - you take the Web space you can get - but I've bundled
                          up the files as an easily accessible .zip file, which others may find more
                          convenient:


                          Can you please provide some general tips as to how I can improve my
                          style of coding ?
                          Yes, but that reply will take some time to write. *This* reply is really
                          just to facilitate easy access to your code, for the convenience of others
                          who may want to help you too. I'll get back to you - watch this space.

                          --
                          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

                          • Spiros Bousbouras

                            #14
                            Re: problem with output of the program on different OS

                            On 9 May, 07:20, pereges <Brol...@gmail. comwrote:
                            On May 9, 10:52 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
                            >
                            Debuggers are over-rated by some people, and can be a huge time sink if
                            used flailingly.
                            Yes, I agree with you that the comment about design was misguided. Module
                            boundaries should be drawn to reflect differences in functionality. The
                            idea that you have some kind of Procrustean source bed, such that any file
                            longer than N lines must be split, is silly.
                            Is that zip file ready yet?
                            >
                            http://www.savefile.com/files/1547165
                            I've been to the page ; I don't see how to download
                            your file. I tried both Firefox and Lynx.

                            Comment

                            • Richard Heathfield

                              #15
                              Re: problem with output of the program on different OS

                              Spiros Bousbouras said:
                              On 9 May, 07:20, pereges <Brol...@gmail. comwrote:
                              >On May 9, 10:52 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
                              >>
                              Debuggers are over-rated by some people, and can be a huge time sink
                              if used flailingly.
                              Yes, I agree with you that the comment about design was misguided.
                              Module boundaries should be drawn to reflect differences in
                              functionality. The idea that you have some kind of Procrustean source
                              bed, such that any file longer than N lines must be split, is silly.
                              Is that zip file ready yet?
                              >>
                              >http://www.savefile.com/files/1547165
                              >
                              I've been to the page ; I don't see how to download
                              your file. I tried both Firefox and Lynx.
                              I struggled too, but managed it in the end. I copied it to my site, from
                              where you can easily get it:



                              --
                              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

                              Working...