This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: On character constants


On 02/02/2010 09:47 AM, Tobias Burnus wrote:
> On 02/02/2010 09:09 AM, Arjen Markus wrote:
>> just out of curiosity, can you give an example of such a corner case?
>>   
>
> Not ad hoc,

Not really a corner case, but what length should a compiler assume as
length in a constructor? The largest, the one of the first argument? the
one of the first constant length?

If one thinks of how to implement it, it becomes also quite difficult:
Currently, as soon as one knows one length, one can reserve
<length>*<#of elements> memory and put all the results together. If one
takes the largest one, one needs to iterate through all elements,
potentially creating lots of temporary variables just to find out the
length from the last function call. -- In case of initialization
expressions, it is easier. If you try with GCC 4.3 or ifort and
string-lengths which are only know at run time, the result can be
unexpected.

Try the following and tell beforehand what it should print. Try it with
your favourite compiler and tell me whether it is what you expected -
and what one should expect.

call test("A")
call test("Abcdef")
contains
subroutine test(a)
character(len=*) :: a
print '(4(">",a,"<":" "))', (/ f(1), f(2), f(3) /)
print '(4(">",a,"<":" "))', (/ f(1), f(2), f(3),a /)
end subroutine test
function f(n)
  character(len=n) :: f
  f = 'abcdefghijklmn'
end function f
end

Tobias

PS: A couple of blank lines below, I have posted the result of some
compilers.

































ifort:
>a  < >ab < >abc<
>a< >a< >a< >A<
>a  < >ab < >abc<
>a     < >ab    < >abc   < >Abcdef<

gfortran 4.3:
>a  < >ab < >abc<
>a< >a< >a< >A<
>a  < >ab < >abc<
>a     < >ab    < >abc   < >Abcdef<

gfortran 4.4:
>a< >a< >a<
>a< >a< >a< >A<
>a< >a< >a<
>a< >a< >a< >A<

openf95:
>a  < >ab < >abc<
>a  < >ab < >abc< >A  <
>a  < >ab < >abc<
>a  < >ab < >abc< >Abc<


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]