Loading ...
Sorry, an error occurred while loading the content.
 

Re: [hackers-il] change the value of 4

Expand Messages
  • Oleg Goldshmidt
    ... I can easily believe that there were implementations that did just that. However, normally you ll segfault in any sane compiler, I believe. G77 is not
    Message 1 of 9 , Feb 17, 2002
      "Nadav Har'El" <nyh@...> writes:

      > Now, here comes the problem: What does fortran do when you call F(4)? It
      > cannot pass the literal "4", and must instead set up a memory space, put
      > a 4 in it, and give F the pointer to that memory space. One implementation
      > I checked (and it will be interesting to check if g77 also does this) chooses
      > not to reset that memory position to 4 on every call to F(4). So if F changes
      > its parameter to 5 (remember, it is allowed to do that), the next calls to
      > F(4) might actually give F a parameter 5! The compiler might (and I don't
      > remember checking that) even use the same memory location for several "4"s
      > mentioned in the program, so all 4s are changed into 5s :)

      I can easily believe that there were implementations that did just that.
      However, normally you'll segfault in any sane compiler, I believe.

      G77 is not smart enough to warn you at compile time that you are
      trying to do something illegal. The following code

      subroutine f(x)
      integer*4 x
      write(6,*) x
      x = 5
      end

      program four
      call f(4)
      call f(5)
      stop
      end

      compiles cleanly with g77 and segfaults at "x = 5" at run time. This
      is, of course, the same behaviour as in your "ruin" C example.

      --
      Oleg Goldshmidt | ogoldshmidt@...
      If it aint't broken it hasn't got enough features yet.
    Your message has been successfully submitted and would be delivered to recipients shortly.