# Strange behaviour when using type(\*) and character(\*) in GFortran

**URL:** <https://fortran-lang.discourse.group/t/strange-behaviour-when-using-type-and-character-in-gfortran/6233>\
**Category:** Help\
**Created:** [July 26, 2023, 3:59pm UTC](https://fortran-lang.discourse.group/t/strange-behaviour-when-using-type-and-character-in-gfortran/6233 "2023-07-26T15:59:15Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Carltoffel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/carltoffel/32/1680_2.png) [@Carltoffel](https://fortran-lang.discourse.group/u/Carltoffel)\
**Post date:** [July 26, 2023, 6:08pm UTC](https://fortran-lang.discourse.group/t/strange-behaviour-when-using-type-and-character-in-gfortran/6233/5 "2023-07-26T18:08:54Z")

</div>

> [@mEm](#):
>
> use `class(*)` instead of `type(*)`

Thanks, this is an easy hack which should do the trick.

> [@mEm](#):
>
> make the useless var **assumed rank**

It actually is in the original code.

> [@mEm](#):
>
> why to even pass it in the first place… so I fear you actually do use it

I don’t use the value, but I need it to check if maybe is unallocated. See your comment [here](https://fortran-lang.discourse.group/t/how-to-have-a-generic-interface-for-both-allocatable-and-non-allocatable-dummy/6114/19).

A more complete example what I’m trying to do would be this:

```auto
implicit none

character(:), allocatable :: not_used
call sub(not_used, "123")
call sub("1", "123")

contains

    subroutine sub(useless_var, print_this)
        class(*), intent(in) :: useless_var(..)
        character(*), intent(in) :: print_this
        print *, "should be 123: '", print_this, "'"
        print *, "useless_var is unallocated", is_unallocated(useless_var)
    end subroutine sub

    logical function is_unallocated(var)
        class(*), intent(in), optional :: var(..)
        is_unallocated = .not. present(var)
    end function is_unallocated

end

```

Followup question: Should I use `type(*)` or `class(*)` for the `is_unallocated` function? What’t the difference beside bypassing a GFortran bug?

---

_[View the full topic](https://fortran-lang.discourse.group/t/strange-behaviour-when-using-type-and-character-in-gfortran/6233)._
