https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98825

--- Comment #3 from max.pd at gmx dot de ---
Here some details to outline the issue:

The problem is affecting

1) "gcc/libgfortran/io/format.c"
2) "gcc/libgfortran/io/transfer.c"

of the gcc source tree.


The feature, implemented as FMT_DOLLAR
can be found in "format.c" (lines 794 to 798)

794:  case FMT_DOLLAR:
795:  get_fnode (fmt, &head, &tail, FMT_DOLLAR);
796:  tail->repeat = 1;
797:  notify_std (&dtp->common, GFC_STD_GNU, "Extension: $ descriptor");
798:  goto between_desc;

--> calling "get_fnode" with FMT_DOLLAR in "format.c" (lines 215-242)

215:  get_fnode (format_data *fmt, fnode **head, fnode **tail, format_token t)
216:  {
217:    fnode *f;
...
238:    f->format = t;
...
241:    return f;
242:  }

f->format is disposed in "transfer.c" (lines 1470-1822)

1462:        t = f->format;
...
1470:        switch (t)
1471:          {
...
1799:          case FMT_DOLLAR:
1800:            consume_data_flag = 0;
1801:            dtp->u.p.seen_dollar = 1;
1802:            break;
...
1822:          }

u.p.seen_dollar for its part determins u.p.eor_condition = 1 
in "transfer.c" (lines 399-400)

399:          if (dtp->u.p.advance_status == ADVANCE_NO ||
dtp->u.p.seen_dollar)
400:            dtp->u.p.eor_condition = 1;

This is the unexpected behavior put forth in this thread.

The '$' feature of a format expression
affects only the end of output, like the
ADVANCE="NO" parameter to the WRITE statement.

So on repeated output, as produced by
multiple records given to a PRINT or WRITE
statement, there is still an unexpected
line break on each record except the last one.
(record is here a set of input values in the format expression)

Yet, in next_record_cc implemented in "transfer.c" (lines 3848 to 3870)
we find no regard of the dtp->u.p.seen_dollar setting
that would lead to the suppression of a Carriage Return,
as it might be expected when using the '$' feature in a format expression

3851:  static void
3852:  next_record_cc (st_parameter_dt *dtp)
3853:  {
...
3865:        /* Output CR for the first character with default CC setting.  */
3866:        *(p++) = dtp->u.p.cc.u.end;
3867:        if (dtp->u.p.cc.len > 1)
3868:          *p = dtp->u.p.cc.u.end;
...
3870:  }

Conclusion:

It should be possible to patch the code here,
leading to a more convenient behavior for the
'$' format extension.

Reply via email to