For Programmers: Free Programming Magazines  


Home > Archive > Fortran > March 2006 > procedure argument









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author procedure argument
Roland Schmehl

2006-03-30, 10:00 pm

a question regarding the usage of procedure arguments with different
argument lists.

the appended code compiles and writes out:

sub1: a= 1.0
sub2: a= 1.0 , b= 2.0

when i replace the two "EXTERNAL sub" statements by interface blocks

INTERFACE
SUBROUTINE sub (a,b)
REAL :: a,b
END SUBROUTINE sub
END INTERFACE

the compiler complains (as it should) about the different number of
arguments of actual and dummy procedure.

why does it accept the EXTERNAL statements?

thanks,
roland


MODULE testmod
INTERFACE
SUBROUTINE sub1 (a)
REAL :: a
END SUBROUTINE sub1
END INTERFACE
INTERFACE
SUBROUTINE sub2 (a,b)
REAL :: a,b
END SUBROUTINE sub2
END INTERFACE
INTERFACE
SUBROUTINE process (sub)
EXTERNAL sub
REAL :: c=1.0,d=2.0
END SUBROUTINE process
END INTERFACE
END MODULE testmod

PROGRAM testprog
USE testmod, ONLY: sub1,sub2,process
CALL process (sub1)
CALL process (sub2)
END PROGRAM testprog

SUBROUTINE process (sub)
EXTERNAL sub
REAL :: c=1.0,d=2.0
CALL sub (c,d)
END SUBROUTINE process

SUBROUTINE sub1 (a)
REAL :: a
WRITE(*,*)'sub1: a= ',a
END SUBROUTINE sub1

SUBROUTINE sub2 (a,b)
REAL :: a,b
WRITE(*,*)'sub2: a= ',a,', b= ',b
END SUBROUTINE sub2
Joe Krahn

2006-03-30, 10:00 pm

Roland Schmehl wrote:
> a question regarding the usage of procedure arguments with different
> argument lists.
>
> the appended code compiles and writes out:
>
> sub1: a= 1.0
> sub2: a= 1.0 , b= 2.0
>
> when i replace the two "EXTERNAL sub" statements by interface blocks
>
> INTERFACE
> SUBROUTINE sub (a,b)
> REAL :: a,b
> END SUBROUTINE sub
> END INTERFACE
>
> the compiler complains (as it should) about the different number of
> arguments of actual and dummy procedure.
>
> why does it accept the EXTERNAL statements?
>
> thanks,
> roland

....snip

Before F90, no procedure prototypes existed, but you could still pass an
external procedure as an argument. EXTERNAL comes from pre-F90. The
current method of procedure "pointer" passing is still somewhat
incomplete. In F2003, you will be able to explicitly declare a procedure
pointer and it's argument prototype.

Joe
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com