From: Terence on
On Sep 23, 1:19 am, Arno <arnoinp...(a)hotmail.com> wrote:
> Dear all,
>
> Find below a piece of code that gives a run-time error with the ifort
> compiler. I thought this to be legal code, but maybe I am overlooking
> something.
>
> Thanks in advance,
>
> Arno
>
> ===========================
> file 1 (main.f90)
>
> program main
>   use my_module
>   call wrapper()
> end program main
>
> ===========================
>
> file 2 (my_module.f90)
>
> module my_module
>
> contains
>
> subroutine wrapper(str)
>   character(9),intent(in),optional :: str
>   call show(str)
> end subroutine wrapper
>
> subroutine show(str)
>   character(9),intent(in),optional :: str
>   if (present(str)) write(*,*) str
> end subroutine show
>
> end module my_module
>
> ==========================
>
> % ifort -V
> Intel(R) Fortran Compiler Professional for applications running on
> IA-32, Version 11.1    Build 20090630 Package ID: l_cprof_p_11.1.046
> Copyright (C) 1985-2009 Intel Corporation.  All rights reserved.
> % ifort  -traceback -ftrapuv -fp-stack-check -check all my_module.f90
> main.f90
> % a.out
> forrtl: severe (408): fort: (18): Dummy character variable 'STR' has
> length 9 which is greater then actual variable length 0
>
> Image              PC        Routine            Line        Source
> a.out              08093FED  Unknown               Unknown  Unknown
> a.out              08092DE5  Unknown               Unknown  Unknown
> a.out              0805FDC8  Unknown               Unknown  Unknown
> a.out              0804ADA9  Unknown               Unknown  Unknown
> a.out              0804B078  Unknown               Unknown  Unknown
> a.out              08049D19  my_module_mp_wrap          11
> my_module.f90
> a.out              08049F5C  MAIN__                      5  main.f90
> a.out              08049CB1  Unknown               Unknown  Unknown
> libc.so.6          B7DAA455  Unknown               Unknown  Unknown
> a.out              08049BC1  Unknown               Unknown  Unknown

Surely variable str should be referred to a INTENT(out) somewhere?
It cannot be INTENT(in) in every reference?
From: Arno on
character(*) solves the problem indeed, as does compiling with -check
all,nobounds. I take the advice to use character(*) from now onwards,
but for the current code I will resort to the compiler flag solution.

Thanks for all the input.

Arno

PS. the if (present) construction works as well, but is very
inconvenient in the actual (and very large) code.
From: Jim Xia on
On Sep 22, 11:19 am, Arno <arnoinp...(a)hotmail.com> wrote:
> Dear all,
>
> Find below a piece of code that gives a run-time error with the ifort
> compiler. I thought this to be legal code, but maybe I am overlooking
> something.
>
> Thanks in advance,
>
> Arno
>
> ===========================
> file 1 (main.f90)
>
> program main
>   use my_module
>   call wrapper()
> end program main
>
> ===========================
>
> file 2 (my_module.f90)
>
> module my_module
>
> contains
>
> subroutine wrapper(str)
>   character(9),intent(in),optional :: str
>   call show(str)
> end subroutine wrapper
>
> subroutine show(str)
>   character(9),intent(in),optional :: str
>   if (present(str)) write(*,*) str
> end subroutine show
>
> end module my_module
>
> ==========================
>
> % ifort -V
> Intel(R) Fortran Compiler Professional for applications running on
> IA-32, Version 11.1    Build 20090630 Package ID: l_cprof_p_11.1.046
> Copyright (C) 1985-2009 Intel Corporation.  All rights reserved.
> % ifort  -traceback -ftrapuv -fp-stack-check -check all my_module.f90
> main.f90
> % a.out
> forrtl: severe (408): fort: (18): Dummy character variable 'STR' has
> length 9 which is greater then actual variable length 0
>
> Image              PC        Routine            Line        Source
> a.out              08093FED  Unknown               Unknown  Unknown
> a.out              08092DE5  Unknown               Unknown  Unknown
> a.out              0805FDC8  Unknown               Unknown  Unknown
> a.out              0804ADA9  Unknown               Unknown  Unknown
> a.out              0804B078  Unknown               Unknown  Unknown
> a.out              08049D19  my_module_mp_wrap          11
> my_module.f90
> a.out              08049F5C  MAIN__                      5  main.f90
> a.out              08049CB1  Unknown               Unknown  Unknown
> libc.so.6          B7DAA455  Unknown               Unknown  Unknown
> a.out              08049BC1  Unknown               Unknown  Unknown


There is nothing wrong with your code. The standard allows passing
absent OPTIONAL dummy arguments around to another OPTIONAL dummy
arguments.

Cheers,

Jim
From: Steve Lionel on
Arno wrote:

> Find below a piece of code that gives a run-time error with the ifort
> compiler. I thought this to be legal code, but maybe I am overlooking
> something.

As others have noted, ifort is in error here. I have reported this to
the developers, the support ID is DPD200140203.

--
Steve Lionel
Developer Products Division
Intel Corporation
Nashua, NH

For email address, replace "invalid" with "com"

User communities for Intel Software Development Products
http://software.intel.com/en-us/forums/
Intel Software Development Products Support
http://software.intel.com/sites/support/
My Fortran blog
http://www.intel.com/software/drfortran