Announcement

Collapse
No announcement yet.

****ing Fortran

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ****ing Fortran

    Why is it that if I do this:

    Code:
          IMPLICIT DOUBLE PRECISION (A-H, O-Z)
          IMPLICIT INTEGER(I-N)
          ISTART=7
          I = IRCON(ISTART)
          RETURN
          END
    
          INTEGER FUNCTION IRCON(ISTART)
          IMPLICIT DOUBLE PRECISION (A-H, O-Z)
          IMPLICIT INTEGER(I-N)
          ISTART=5
          RETURN
          END
    but if I do this

    Code:
          IMPLICIT DOUBLE PRECISION (A-H, O-Z)
          IMPLICIT INTEGER(I-N)
          I = IRCON(7)
          RETURN
          END
    
          INTEGER FUNCTION IRCON(ISTART)
          IMPLICIT DOUBLE PRECISION (A-H, O-Z)
          IMPLICIT INTEGER(I-N)
          ISTART=5
          RETURN
          END
    I segfault?

    I understand passing by reference, but why can't I simply manipulate ISTART as a local variable when I pass the 7 by value?
    12-17-10 Mohamed Bouazizi NEVER FORGET
    Stadtluft Macht Frei
    Killing it is the new killing it
    Ultima Ratio Regum

  • #2
    own goal
    "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
    Ben Kenobi: "That means I'm doing something right. "

    Comment


    • #3
      Reread. I hit alt-s before completing by mistake
      12-17-10 Mohamed Bouazizi NEVER FORGET
      Stadtluft Macht Frei
      Killing it is the new killing it
      Ultima Ratio Regum

      Comment


      • #4
        I'm assuming IRCON is some function/procedure you wrote.

        I'm also assuming it is expecting a memory address, eg a variable name, rather than just a number.

        Thus it's trying to access 0x7 in memory, which is outside of its segment, triggering a segfault.
        "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
        Ben Kenobi: "That means I'm doing something right. "

        Comment


        • #5
          Can't be that simple because:

          Code:
                IMPLICIT DOUBLE PRECISION (A-H, O-Z)
                IMPLICIT INTEGER(I-N)
                I = IRCON(7)
                RETURN
                END
          
                INTEGER FUNCTION IRCON(ISTART)
                IMPLICIT DOUBLE PRECISION (A-H, O-Z)
                IMPLICIT INTEGER(I-N)
                PRINT *, ISTART
                RETURN
                END
          outputs 7 to term, not some random string of gibberish
          12-17-10 Mohamed Bouazizi NEVER FORGET
          Stadtluft Macht Frei
          Killing it is the new killing it
          Ultima Ratio Regum

          Comment


          • #6
            (by the way, this is obviously not a real program; I hit a segfault and manage to reduce it down to this simple example)
            12-17-10 Mohamed Bouazizi NEVER FORGET
            Stadtluft Macht Frei
            Killing it is the new killing it
            Ultima Ratio Regum

            Comment


            • #7
              So fortran understands passing by value because it's got the right integer when I print from the function

              But it refuses to manipulate that variable locally. That makes no sense to me.
              12-17-10 Mohamed Bouazizi NEVER FORGET
              Stadtluft Macht Frei
              Killing it is the new killing it
              Ultima Ratio Regum

              Comment


              • #8
                (also note that I've fixed the problem by simply using variable names everywhere I call a function, but it still bothers me; this makes no sense)
                12-17-10 Mohamed Bouazizi NEVER FORGET
                Stadtluft Macht Frei
                Killing it is the new killing it
                Ultima Ratio Regum

                Comment


                • #9
                  Which compiler are you using? gcc?
                  "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                  Ben Kenobi: "That means I'm doing something right. "

                  Comment


                  • #10
                    g77
                    12-17-10 Mohamed Bouazizi NEVER FORGET
                    Stadtluft Macht Frei
                    Killing it is the new killing it
                    Ultima Ratio Regum

                    Comment


                    • #11
                      g77 has some Fortran90 elements in it (like ENDDO, long variable names etc)

                      but there shouldn't be major differences in things like call by reference/value, should there (between f77 and g77)
                      12-17-10 Mohamed Bouazizi NEVER FORGET
                      Stadtluft Macht Frei
                      Killing it is the new killing it
                      Ultima Ratio Regum

                      Comment


                      • #12
                        Do you have another compiler or version of the compiler to try? It looks fine to me, but I've not done Fortran in a while now and most of my stuff was not Fortran 77.
                        "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                        Ben Kenobi: "That means I'm doing something right. "

                        Comment


                        • #13
                          I can try gfortran, I suppose
                          12-17-10 Mohamed Bouazizi NEVER FORGET
                          Stadtluft Macht Frei
                          Killing it is the new killing it
                          Ultima Ratio Regum

                          Comment


                          • #14
                            I sent this to a friend of mine on the IBM Fortran compiler devteam, we'll see what he says.
                            "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                            Ben Kenobi: "That means I'm doing something right. "

                            Comment


                            • #15
                              gfortran gives same result
                              12-17-10 Mohamed Bouazizi NEVER FORGET
                              Stadtluft Macht Frei
                              Killing it is the new killing it
                              Ultima Ratio Regum

                              Comment

                              Working...
                              X