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: determining length of substring?


On Saturday 23 April 2005 03:57, Steve Kargl wrote:
> > In general you can only check things that are constant expressions. For
> > everything everything else just punt and generate a runtime check at the
> > tree level, conditional on -fbounds-check.
>
> For ichar(), we want an unconditional error.  The standard says
> that the argument to ichar() "shall be of type character and of
> length one," unless you want to support an extension.

This is a requirement, not a constraint. ie. the compiler is not required to 
diagnose it, and can do whatever it likes if the user calls ichar with a 
length not equal to one.

I'm not suggesting we support lengths other than one, just that we can't 
always diagnose it. For example:

subroutine sub(i, n)
  integer :: i, n
  character :: c = 'abcd'

  print *, ichar(c(i:n))
end subroutine 

This is perfectly legal, provided i and n are always equal. We can't prove 
this at compile time, so we either have to trust the user or generate a 
runtime check.

> I have a gfc_check_ichar() function that can deal with some of
> the checking.  

Right. This is where compile time errors should be generated.

> Would you rather have this restriction on length 1 
> checked only in 1 place (ie., at the tree level)?

No. Compile time errors should be generated in the frontend. Runtime checks 
should be [optionally] generated at the tree level. We already do this for 
arrays. If an array expression has constant shape we check conformance in the 
frontend at compile time. Otherwise we generate a runtime check. The runtime 
check is omitted when -fno-bounds-check (the default).

It's acceptable for the compile time checks to only catch the easy cases.
It the optimizers can also eliminate some of the runtime checks, that's also 
good. That's what they're there for.

Paul


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