Re: static function ? how ?




Hi,

KC wrote:

> Hi,
>
> In C language, we can use:
>
> /* foo.c */
> static void foo(void)
> {
> ...
> }
>
>
> to define a static function "foo" which is
> local function of file "foo.c".
>
> Can I do the same thing in Fortran ? How ?
> I'm using g77. Thanks.
>
>

You can't in F77, so why not upgrade to F90 ? Your URL
suggests that you can get a copy of the Intel compiler for free.

You can't do exactly the same in F90, as there is no such thing as file
scope, but you can do something very similar with modules:

Module baz

Implicit None

Public :: bar ! The outside world can see bar

Private ! By default nothing can be seen in the module
! unless declared public

Contains

Subroutine foo( ... ) ! Private, so can only be seen by routines in
! the module
....
End Subroutine foo

Subroutine bar( ... ) ! Public, so can be seen outside the module
....
End Subroutine bar

End Module baz

Modules provide mechanisms that are much more powerful than the simple
file scope provided by C, so I would strongly suggest you look into them,

Hope this helps,

Ian


.



Relevant Pages

  • Re: explicit interface implementation does not work with events
    ... For some reason you need to perform explicit registration in this case ... Bar b = new Bar; ... private static void f_Foo ... EventHandler foo; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Difference between :: and ->
    ... instanciated upon the first call to any of its static members. ... What instance of Foo does that last line refer to? ... a global instance that was instanciated upon the call to bar(). ... actually, it is...just not callable outside of self or parent...that's why you can have a shared private static variable within a class and reference it between static function calls...all the while, retaining it's changing value. ...
    (comp.lang.php)
  • Re: Difference between :: and ->
    ... instanciated upon the first call to any of its static members. ... What instance of Foo does that last line refer to? ... a global instance that was instanciated upon the call to bar(). ... it between static function calls...all the while, ...
    (comp.lang.php)
  • static function ? how ?
    ... static void foo ... to define a static function "foo" which is ... local function of file "foo.c". ...
    (comp.lang.fortran)
  • Re: [PATCH] HID: avoid sparse warning in HID_COMPAT_LOAD_DRIVER
    ... surely this could simply be changed to 'static void ... 00000005 T bar ... i.e. foo is local ...
    (Linux-Kernel)