# Does a generic interface shadow a dangling procedure with the same name?

**URL:** <https://fortran-lang.discourse.group/t/does-a-generic-interface-shadow-a-dangling-procedure-with-the-same-name/10401>\
**Category:** Help\
**Created:** [September 12, 2025, 10:00am UTC](https://fortran-lang.discourse.group/t/does-a-generic-interface-shadow-a-dangling-procedure-with-the-same-name/10401 "2025-09-12T10:00:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [September 12, 2025, 10:00am UTC](https://fortran-lang.discourse.group/t/does-a-generic-interface-shadow-a-dangling-procedure-with-the-same-name/10401/1 "2025-09-12T10:00:34Z")

</div>

See the code below. It has 2 dangling routines `foo()` and `foo_1()`. In the program, an explicit interface is defined for `foo_1()`, and then `foo_1()` is listed under generic interface `foo`. That is, the generic interface `foo` has the same name as the dangling routine `foo()`.

In all compilers I have tested (gfortran, ifx, nvfortran, flang, lfortran) the behavior is:

- no name conflict at compilation
- the generic interface “shadows” the dangling routine; that is, the program always prints `"foo_1"`  
[Compiler Explorer](https://godbolt.org/z/eqcvoo486)

I guess then this is guaranteed by the standard (all the more than even with all warnings enabled, the compilers do not complain)… But it’s only a guess. Any comment?

```auto
subroutine foo()
    print*, "foo"
end subroutine

subroutine foo_1()
    print*, "foo_1"
end subroutine

program bar

    interface
        subroutine foo_1()
        end subroutine
    end interface

    interface foo
        procedure foo_1
    end interface

    call foo()

end

```

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [September 12, 2025, 9:39pm UTC](https://fortran-lang.discourse.group/t/does-a-generic-interface-shadow-a-dangling-procedure-with-the-same-name/10401/2 "2025-09-12T21:39:21Z")

</div>

It’s invalid to refer to a generic identifier if it does not have a specific procedure with an interface compatible with the reference. So, in the example, the call must be referring to the only specific procedure with that generic identifier, that being `foo_1`.

Thus the answer to the question is yes, a generic identifier makes it impossible to call an external procedure with the same name via an implicit interface.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [September 13, 2025, 8:10am UTC](https://fortran-lang.discourse.group/t/does-a-generic-interface-shadow-a-dangling-procedure-with-the-same-name/10401/3 "2025-09-13T08:10:35Z")

</div>

That’s fine, this is the behavior I really want.

---

<div class="post-metadata">

**Author:** ![ashe](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@ashe](https://fortran-lang.discourse.group/u/ashe)\
**Post date:** [September 13, 2025, 3:09pm UTC](https://fortran-lang.discourse.group/t/does-a-generic-interface-shadow-a-dangling-procedure-with-the-same-name/10401/4 "2025-09-13T15:09:40Z")

</div>

> [@everythingfunctional](#):
>
> Thus the answer to the question is yes, a generic identifier makes it impossible to call an external procedure with the same name via an implicit interface.

Not impossible but inconvenient. You can still call the external `foo` like this if you really need to:

```auto
    block
        external foo
        call foo()
    end block

```
