This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [PATCH] fortran/28213 -- Fix Hollerith in IO list
- From: Feng Wang <wf_cs at yahoo dot com>
- To: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- Cc: Jerry DeLisle <jvdelisle at verizon dot net>, fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Wed, 5 Jul 2006 11:52:14 +0800 (CST)
- Subject: Re: [PATCH] fortran/28213 -- Fix Hollerith in IO list
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=UGWQHaoSybXhIkrjQeUsCIlbiS/NgV7ft+jLqNdd0f3FaKJpntqxWWv7ovhhni1J3rps+RPegzuW4Nmr+URwBzLyayzoFaBTOzS5I4nefbobi4MLqkFr5Y+x4yZtFRf0r9XrAKPPfDghxO2C8ECAxT6utYdB8O8RrAFj1PZigiQ= ;
--- Steve Kargl <sgk@troutmask.apl.washington.edu> wrote:
> On Tue, Jul 04, 2006 at 08:21:54AM -0700, Steve Kargl wrote:
> > On Tue, Jul 04, 2006 at 10:26:55PM +0800, Feng Wang wrote:
> >>
> >> --- Jerry DeLisle <jvdelisle@verizon.net>????:
> >>
> >>> Steve Kargl wrote:
> >>
> >
> >>From Fortran 66, 5.1.1.6, page 10.
> >
> > "This type of constant may be written only in the argument list
> > of a CALL statement and in the data initialization statement."
> >
> > There is an ambiguity with a Hollerith constant in an output statement.
> >
> > program z
> > data i/3horz/
> > data x/3horz/
> > print *, i, x
> > c What value should the following list-directed print statement print?
> > c print *, 3horz
> > end
> >
> > Furthermore, see section A2, "Conflicts with ANSI X3.9-1966,"
> > of the Fortran 77 standard. Item (3) says "Hollerith constants
> > and Hollerith data are not permitted in this standard." However,
> > Appendix C, address the use of Hollerith in a Fortran 77
> > program. In particular, section C6 address IO with the A edit
> > descriptor, but my interpretation (which is sometimes known to
> > be too strict and/or wrong) is that a "print '(A3)', 3horz' is
> > not permitted.
Hollerith constant is a more compiler implementation dependency feature. The
legacy specification is less meaningful than the practice codes. This typeless
literal constant was created to be used as character. So I prefer to accept it
to be printed as character type.
> >
> > Finally, the behavior I implemented is consistent with NAG's
> > Fortran 95 compiler.
ifort is consistent with mine :-)
> atlas:kargl[205] cat z.f
> program z
> data i/3horz/
> data x/3horz/
> print *, i, x
> print *, 3horz
> print '(A3)', i
> end
[wf@WFPC bug]$ ifort z.f
[wf@WFPC bug]$ ./a.out
544895599 2.1213687E-19
orz
orz
And IBM XL Fortran V10.1 online documents say:
(http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlf101l.doc/xlflr/typeless_lit_constants.htm)
When you use a typeless constant in any other context, the constant assumes the
default integer type, with the exception of Hollerith constants. Hollerith
constants assume a character data type when used in the following situations:
1. An H edit descriptor
2. A relational operation with both operands being Hollerith constants
3. An input/output list
>
> Sigh. g77 does something completely different from your patch and
> from mine.
>
> atlas:kargl[203] g77 -o z z.f
> atlas:kargl[204] ./z
> 544895599 2.12136866E-19
> 544895599
> orz
>
> g77 converts the Hollerith constant to an integer in list-directed
> output. This means we probably need to implement the g77 behavior
> for backwards compatibility.
>
The patch enclosed implements g77 behavior, but I still think it is better to
print as character type.
Best Regards,
Feng Wang
--
Creative Compiler Research Group,
National University of Defense Technology, China.
___________________________________________________________
Mp3疯狂搜-新歌热歌高速下
http://music.yahoo.com.cn/?source=mail_mailbox_footer
Index: io.c
===================================================================
--- io.c £¨ÐÞ¶©°æ 115177£©
+++ io.c £¨¹¤×÷¿½±´£©
@@ -26,6 +26,7 @@ Software Foundation, 51 Franklin Street,
#include "gfortran.h"
#include "match.h"
#include "parse.h"
+#include "intrinsic.h"
gfc_st_label format_asterisk =
{0, NULL, NULL, -1, ST_LABEL_FORMAT, ST_LABEL_FORMAT, NULL,
@@ -2132,6 +2133,11 @@ match_io_element (io_kind k, gfc_code **
gfc_free_expr (expr);
return MATCH_ERROR;
}
+ if ((k == M_WRITE || k == M_PRINT) && expr->expr_type == EXPR_CONSTANT
+ && expr->ts.type == BT_HOLLERITH)
+ {
+ expr = gfc_convert_constant (expr, BT_INTEGER, gfc_default_integer_kind);
+ }
cp = gfc_get_code ();
cp->op = EXEC_TRANSFER;