Vector arguments to external procedures - correction 
Author Message
 Vector arguments to external procedures - correction

Sorry - in my earlier message, instead of

Quote:
>     int x[100];
>     foo(*(x+30), 10);

I meant of course

    foo(x+30, 10);

since I want to pass the address, not the value.

The fortran, by the way, is correct, since Fortran always passes
addresses.

David



Sat, 08 Oct 2005 01:23:09 GMT  
 Vector arguments to external procedures - correction


Quote:
> Sorry - in my earlier message, instead of

> >     int x[100];
> >     foo(*(x+30), 10);

> I meant of course

>     foo(x+30, 10);

> since I want to pass the address, not the value.

> The Fortran, by the way, is correct, since Fortran always passes
> addresses.

Irrelevant reminiscence: many years ago, I changed the value of 2 this way.

I had a (Fortran) subroutine which incremented one of its parameters. Later,
I called this subroutine with the constant 2. Later still, I used 2 in an
arithmetic expression: something like,

    ...
    CALL FOO(N, 2, X, Y)
    ...
    J = J + 2
    ...

it took me quite a while to discover that J was being incremented by 3 .....

Ah, those were the days ;-).

Jonathan
(I believe the compiler was "smart" enough to use the same storage for
identical
constants, to save memory.)



Sat, 08 Oct 2005 23:33:22 GMT  
 Vector arguments to external procedures - correction

Quote:
> Irrelevant reminiscence: many years ago, I changed the value of 2 this way.

>...

> Ah, those were the days ;-).

Were?? Well, I suppose there has been some progress - under present-day
Solaris, using Sun's Fortran compiler, this program:

      subroutine foo(x)
      x = x + 1
      return
      end

      call foo(2)
      end

produces a run-time error with the message "POSSIBLE ATTEMPT TO MODIFY
CONSTANT" followed by a segmentation fault!

And in "Structured Fortran 77 Programming with Hewlett-Packard
Computers" I read "Since a constant is meant to be a value not subject
to change, it should be used [as an actual argument] in those instances
where the subprogram's computations do not alter it."

Maybe you didn't read the manual.

David



Sun, 09 Oct 2005 18:34:16 GMT  
 Vector arguments to external procedures - correction


Quote:
> > Irrelevant reminiscence: many years ago, I changed the value of 2 this
way.

> > Ah, those were the days ;-).

> Were?? Well, I suppose there has been some progress - under present-day
> Solaris, using Sun's Fortran compiler, this program:
(snip)
> CONSTANT" followed by a segmentation fault!

> And in "Structured Fortran 77 Programming with Hewlett-Packard
> Computers" I read "Since a constant is meant to be a value not subject
> to change, it should be used [as an actual argument] in those instances
> where the subprogram's computations do not alter it."

> Maybe you didn't read the manual.

Manual? Manual? We don't need no steeenking manuals!

But I didn't realise the Fortran 77 manual was retrospective back to Fortan
IV
in 1972 :-). I'm afraid my memory for the documentation I didn't have more
than
thirty years ago (gosh, doesn't time fly?) is not complete. But I can still
remember
my bugs! :-).

Did I ever tell you about my (Fortran) draughts (checkers) program which
only had
one known bug? The bug was that it printed the following message:

   "THERE IS A BUG"

The bug was caused by a missing GOTO before the WRITE statement that printed
the message.

However, in view of this bug, it wasn't a bug. In which case it was.

Jonathan



Sun, 09 Oct 2005 19:46:48 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Vector arguments to external procedures

2. Vector arguments to external procedures

3. Vector arguments to external procedures

4. procedure as dummy argument (was: EXTERNAL and INTRINSIC statement)

5. Procedure Argument/External

6. Passing module procedures to external procedures -- type issues

7. Defining procedures whose argument list is result of procedure

8. passing functions with variable number of arguments as procedure arguments

9. Procedures as arguments - set dummy arguments

10. no vector = vector*vector in BLAS?

11. PROCEDURE + answer -- a correction

12. vector valued function as argument

 

 
Powered by phpBB® Forum Software