public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Someone has caused regressions in gfortran (c_char_tests_red.f03, now PR33330)
@ 2007-09-07 12:39 Dominique Dhumieres
  2007-09-07 12:47 ` François-Xavier Coudert
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Dominique Dhumieres @ 2007-09-07 12:39 UTC (permalink / raw)
  To: gcc; +Cc: hubicka, fortran

In comment #7 of PR33330, Richard Guenther asked the following question 
I cannot answer:

> Btw, is it mandated by the fortran standard to pass a scalar as array
> reference?

Does anyone knows the answer? or should it be asked on comp.lang.fortran?

TIA

Dominique

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Someone has caused regressions in gfortran (c_char_tests_red.f03, now PR33330)
  2007-09-07 12:39 Someone has caused regressions in gfortran (c_char_tests_red.f03, now PR33330) Dominique Dhumieres
@ 2007-09-07 12:47 ` François-Xavier Coudert
  2007-09-07 13:07 ` Tobias Burnus
  2007-09-07 13:18 ` Tim Prince
  2 siblings, 0 replies; 6+ messages in thread
From: François-Xavier Coudert @ 2007-09-07 12:47 UTC (permalink / raw)
  To: Dominique Dhumieres; +Cc: gcc, hubicka, fortran

> Does anyone knows the answer? or should it be asked on comp.lang.fortran?

It's very specific to the problem at hand, so I doubt c.l.f could give
us much input on that. As I understand, in this case, it actually is
the right thing to do.

FX

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Someone has caused regressions in gfortran (c_char_tests_red.f03,  now PR33330)
  2007-09-07 12:39 Someone has caused regressions in gfortran (c_char_tests_red.f03, now PR33330) Dominique Dhumieres
  2007-09-07 12:47 ` François-Xavier Coudert
@ 2007-09-07 13:07 ` Tobias Burnus
  2007-09-07 13:18 ` Tim Prince
  2 siblings, 0 replies; 6+ messages in thread
From: Tobias Burnus @ 2007-09-07 13:07 UTC (permalink / raw)
  To: Dominique Dhumieres; +Cc: gcc, fortran

Salut Dominique, moin Richard, hello all,

(Answering Richard's question from PR33330.)
Dominique Dhumieres wrote:
>> Btw, is it mandated by the fortran standard to pass a scalar as array
>> reference?
>>     
> Does anyone knows the answer? or should it be asked on comp.lang.fortran?
>   

The standard mandates that (when the dummy argument has no VALUE
attribute) variables are passed as reference; I'm pretty sure that the
rest is implementation dependent. I think the question arose form:

   character :: my_char

which is a scalar character variable which takes exactly one character.
However, the following is also a scalar variable:

   character(len=10) :: my_char

which contains 10 characters. It has the same storage size as an array
with ten elements with one character each:

  character(len=1), dimension(10) :: my_char

As a scalar character variable with len > 1 needs an array reference, it
is quite natural to pass also a scalar variable with length 1 as array
reference.

I think the standard also allows to pass it as non-array reference,
which happens (for obvious reasons) if one uses C Bindings. (In this
case the standard mandates len=1; for strings one has thus to use an array.)


Hmm, thinking it over, I think on can say that the standard mandates
that an array reference is passed. Let's assume two functions,
expecting, respectively,

  character(len=1) :: arg
  character(len=*) :: arg

(len=* allows for any lengths; the length is passed as an additional
argument in both cases.)

In the main program I do now:
  call mySubroutine( 'a' )

in order to decide whether one needs to pass an array reference or not,
one needs to know whether len=1 or len=*. This is only possible if one
knows the explicit interface (= function definition); but Fortran allows
also implicit interfaces (i.e. "assume mySubroutine exists, it returns
VOID and takes 0 to oo arguments of a certain but unknown type").

Tobias

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Someone has caused regressions in gfortran (c_char_tests_red.f03,  now PR33330)
  2007-09-07 12:39 Someone has caused regressions in gfortran (c_char_tests_red.f03, now PR33330) Dominique Dhumieres
  2007-09-07 12:47 ` François-Xavier Coudert
  2007-09-07 13:07 ` Tobias Burnus
@ 2007-09-07 13:18 ` Tim Prince
  2007-09-07 13:38   ` Richard Guenther
  2 siblings, 1 reply; 6+ messages in thread
From: Tim Prince @ 2007-09-07 13:18 UTC (permalink / raw)
  To: Dominique Dhumieres; +Cc: gcc, hubicka, fortran

Dominique Dhumieres wrote:
> In comment #7 of PR33330, Richard Guenther asked the following question 
> I cannot answer:
> 
>> Btw, is it mandated by the fortran standard to pass a scalar as array
>> reference?
> 
> Does anyone knows the answer? or should it be asked on comp.lang.fortran?
> 
Here, it looks as if you mean passing a character string of length 1 as
a variable length string.  Certainly, this should be no problem.  Pardon
me if I misunderstood.
In either case, there should be plenty of references in c.l.f archives.
  In general, passing a scalar where an array reference is required is
non-standard and a serious portability issue.  Use of module or
interface syntax should cause any problems to be diagnosed.
For CHARACTER type, there is a distinction between an array (of
character strings, possibly of length 1) and a scalar character string.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Someone has caused regressions in gfortran (c_char_tests_red.f03, now PR33330)
  2007-09-07 13:18 ` Tim Prince
@ 2007-09-07 13:38   ` Richard Guenther
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Guenther @ 2007-09-07 13:38 UTC (permalink / raw)
  To: Tim Prince; +Cc: Dominique Dhumieres, gcc, hubicka, fortran

On 9/7/07, Tim Prince <tprince@computer.org> wrote:
> Dominique Dhumieres wrote:
> > In comment #7 of PR33330, Richard Guenther asked the following question
> > I cannot answer:
> >
> >> Btw, is it mandated by the fortran standard to pass a scalar as array
> >> reference?
> >
> > Does anyone knows the answer? or should it be asked on comp.lang.fortran?
> >
> Here, it looks as if you mean passing a character string of length 1 as
> a variable length string.  Certainly, this should be no problem.  Pardon
> me if I misunderstood.
> In either case, there should be plenty of references in c.l.f archives.
>   In general, passing a scalar where an array reference is required is
> non-standard and a serious portability issue.  Use of module or
> interface syntax should cause any problems to be diagnosed.
> For CHARACTER type, there is a distinction between an array (of
> character strings, possibly of length 1) and a scalar character string.

What I was after in this particular context is that the miscompilation
would have
not occured if the frontend passed the character as char* and did the
de-reference
as plain indirect reference instead of an array reference.

Richard.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Someone has caused regressions in gfortran (c_char_tests_red.f03, now PR33330)
@ 2007-09-07 11:38 Dominique Dhumieres
  0 siblings, 0 replies; 6+ messages in thread
From: Dominique Dhumieres @ 2007-09-07 11:38 UTC (permalink / raw)
  To: gcc; +Cc: hubicka, fortran

This is now PR33330 handled by Richard Guenther.

Dominique

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-09-07 13:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-07 12:39 Someone has caused regressions in gfortran (c_char_tests_red.f03, now PR33330) Dominique Dhumieres
2007-09-07 12:47 ` François-Xavier Coudert
2007-09-07 13:07 ` Tobias Burnus
2007-09-07 13:18 ` Tim Prince
2007-09-07 13:38   ` Richard Guenther
  -- strict thread matches above, loose matches on Subject: below --
2007-09-07 11:38 Dominique Dhumieres

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).