[comp.lang.misc] Too small field width

pattis@june.cs.washington.edu (Richard Pattis) (07/25/89)

In Pascal, when one specifies a too small field width, my compiler prints the
"*" character replicated to fill the field width.  My Modula-2 compiler
prints the full value, in as few characters as possible, disregarding the
field width if it is too small (0 is commonly used to mean "print the value
in the fewest number of characters").

Are there any languages/compilers out there that are known, in such a case,
to keep the field width and print just some of value (for a number, either
left or right truncated)? I thought FORTRAN IV did this, but the referece I
have says no.  Maybe an earlier FORTRAN?

Rich Pattis

diamond@csl.sony.co.jp (Norman Diamond) (07/26/89)

In article <8782@june.cs.washington.edu> pattis@june.cs.washington.edu (Richard Pattis) writes:

>In Pascal, when one specifies a too small field width, my compiler prints the
>"*" character replicated to fill the field width.

You don't have a Pascal compiler.  The Pascal standard (even the old
one; even J&W) calls for printing the value.

>My Modula-2 compiler
>prints the full value, in as few characters as possible, disregarding the
>field width if it is too small (0 is commonly used to mean "print the value
>in the fewest number of characters").

Like Pascal compilers do.  I'd suggest you return yours to the vendor
and demand a refund.  Warranty exclusions don't generally mention
blatant misrepresentation.

>Are there any languages/compilers out there that are known, in such a case,
>to keep the field width and print just some of value (for a number, either
>left or right truncated)? I thought FORTRAN IV did this, but the referece I
>have says no.  Maybe an earlier FORTRAN?

Fortran II did that.  Fortran IV printed stars.

I think you might be able to get truncation out of PL/I.

--
-- 
Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.jp@relay.cs.net)
  The above opinions are inherited by your machine's init process (pid 1),
  after being disowned and orphaned.  However, if you see this at Waterloo or
  Anterior, then their administrators must have approved of these opinions.

sommar@enea.se (Erland Sommarskog) (07/28/89)

Richard Pattis (pattis@june.cs.washington.edu) writes:
>In Pascal, when one specifies a too small field width, my compiler prints the
>"*" character replicated to fill the field width.  My Modula-2 compiler
>prints the full value, in as few characters as possible, disregarding the
>field width if it is too small (0 is commonly used to mean "print the value
>in the fewest number of characters").

Strange compiler you have. All Pascal compilers I have dealt with
just expands the field so that the item fits. I don't have Wirth's
report around, but to me it sounds like your compiler deviates from
the standard. Fortran should behave in that way, I think, but not Pascal.

>Are there any languages/compilers out there that are known, in such a case,
>to keep the field width and print just some of value (for a number, either
>left or right truncated)?

Cobol. At least the report writer does so. At least in DEC's compiler
for VMS. Say you state that field should look like:
      z.zzz.zzz.zz9,99 BLANK WHEN ZERO
(The z means leave blank if they are zero. The dots and commas are
printed if they are preceeded by numbers. The BLANK WHEN ZERO prevents
0,00 from pop up.) Assume now that business goes better than expected
and your result is 10.043.967.234,32 in some currency. This will come up
as 43.967.234,32 in your report, which is not all nice. I haven't found
a way to tell Cobol that it should print stars or whatever in such a
case. The behaviour above is very dangerous, because if you don't have
a very clear idea what results you expect, you might very easily believe
that the truncated field is the actual value.
If there is to make VAX-Cobol behave differently please tell me, because 
we're using the report writer a lot in our project and really have
that problem.
-- 
Erland Sommarskog - ENEA Data, Stockholm - sommar@enea.se
"Apparently being a gnu adept and having a good sense of humor
are disjunct qualities." - Mart van Stiphout