# Ambiguous types message - correct?

**URL:** <https://fortran-lang.discourse.group/t/ambiguous-types-message-correct/11010>\
**Category:** Help\
**Created:** [July 21, 2026, 6:45am UTC](https://fortran-lang.discourse.group/t/ambiguous-types-message-correct/11010 "2026-07-21T06:45:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [July 21, 2026, 6:45am UTC](https://fortran-lang.discourse.group/t/ambiguous-types-message-correct/11010/1 "2026-07-21T06:45:02Z")

</div>

I am working on an interface for a rather larger C library and I encounter a problem with gfortran. The attached code is accepted by Intel Fortran oneAPI and Flang, but not by gfortran. I wonder whether my approach is correct and gfortran is overzealous.

The thing is: the library uses several C structs that on the Fortran side are merely pointers, so type(c\_ptr). I would like to use the renaming feature of the use statement to distinguish the pointers on the Fortran side. So:

```auto
module types
    use iso_c_binding, c_ptr => c_ptr, pointer_x => c_ptr, pointer_y => c_ptr
end module types

```

(or variations)

As said both Intel Fortran oneAPI and Flang accept this, but gfortran comes up with the following messages:

```auto

   46 | type(pointer_y) :: interp
      | 1
Error: Type name 'pointer_y' at (1) is ambiguous
chk_ambiguous.f90:47:20:

   47 | type(pointer_x) :: obj
      | 1
Error: Type name 'pointer_x' at (1) is ambiguous

```

I have tried various ways of avoiding these error messages but to no avail.

So, my question is: is my approach valid or is it simply not allowed to have several “aliases” for the same type?

(Of course, given the current situation I will have to abandon the idea if I want to support gfortran with this.)  
[chk\_ambiguous.f90](https://fortran-lang.discourse.group/uploads/short-url/v3I25HGs4rW3pK4mRLOFQjsjzkD.f90) (1.1 KB)

---

<div class="post-metadata">

**Author:** ![themos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/themos/32/521_2.png) [@themos](https://fortran-lang.discourse.group/u/themos)\
**Post date:** [July 21, 2026, 10:32am UTC](https://fortran-lang.discourse.group/t/ambiguous-types-message-correct/11010/2 "2026-07-21T10:32:44Z")

</div>

`POINTER_X` and `POINTER_Y` are accessible from both modules `AMBIGUOUS_A` and `AMBIGUOUS_B`. Good code hygiene says to always use the ONLY clause with USE.

Some compilers suppress the error by being able to analyze the modules at the same time as the main program unit, and determine that both modules provide identical associations.

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [July 21, 2026, 10:36am UTC](https://fortran-lang.discourse.group/t/ambiguous-types-message-correct/11010/3 "2026-07-21T10:36:48Z")

</div>

Right, but in actual use both types would need to be accessible. The solution would be to hide them in the using modules and require that the user uses the types module in the program?

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [July 21, 2026, 11:34am UTC](https://fortran-lang.discourse.group/t/ambiguous-types-message-correct/11010/4 "2026-07-21T11:34:42Z")

</div>

Yes, that does seem to do the trick. I have attached the improved version.  
[chk\_ambiguous\_v2.f90](https://fortran-lang.discourse.group/uploads/short-url/1srURfclzRg6t3TncIsUwloCPU0.f90) (1.4 KB)

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [July 21, 2026, 4:02pm UTC](https://fortran-lang.discourse.group/t/ambiguous-types-message-correct/11010/5 "2026-07-21T16:02:31Z")

</div>

I’m a little surprised that this compilation fails too. Just out of curiosity, I compiled the code with flang and with nagfor and the compilations all succeed (with warnings about unused arguments, but that’s ok).

> [@Arjen](#):
>
> So, my question is: is my approach valid or is it simply not allowed to have several “aliases” for the same type?

There is no problem with having multiple aliases to the same entity. I experimented with your code by defining multiple aliases to `c_int` (an integer parameter) instead of `c_ptr` (an intrinsic derived type). In this case, gfortran compiled the code with no problem. This looks perhaps like a problem that is specific to `c_ptr`? Here is that working code:

```auto
module types
    use, intrinsic :: iso_c_binding, ik => c_int, jk => c_int
end module types

module ambiguous_a
    use types
    implicit none
contains
   function func_a( i )
      integer(ik) :: func_a
      integer(jk), intent(in) :: i
      func_a = i
   end function func_a
end module ambiguous_a

module ambiguous_b
    use types
    implicit none
contains
   function func_b( i )
      integer(ik) :: func_b
      integer(jk), intent(in) :: i
      func_b = i
   end function func_b
end module ambiguous_b

program use_ab
    use ambiguous_a
    use ambiguous_b
    integer(ik) :: i = 1
    integer(jk) :: j = 2
    print *, func_a(i), func_b(j)
end program use_ab

```

I thought that maybe it was the odd looking alias `c_ptr => c_ptr` causing the problem, but when I did that with `c_int`, the code still worked.

> [@Arjen](#):
>
> Right, but in actual use both types would need to be accessible.

I guess in that case, since they have the same name, you would need to rename or hide one of them in the module where they are both accessible. I’m unsure if this is required by the standard or if it is a workaround for a gfortran compiler bug.

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [July 22, 2026, 6:38am UTC](https://fortran-lang.discourse.group/t/ambiguous-types-message-correct/11010/6 "2026-07-22T06:38:45Z")

</div>

Hm, funny that it should work with a kind parameter but not with a derived type. I guess it is easier to check that the names refer to the same entity than it is with derived types.
