bug-gnucobol
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [open-cobol-list] possibly bug: Compare: numeric (USAGE COMP ...)


From: William M. Klein
Subject: RE: [open-cobol-list] possibly bug: Compare: numeric (USAGE COMP ...) with alphanumeric
Date: Mon May 10 11:47:04 2004

The following is my understanding of what is SUPPOSED to happen according to
both the '85 and 2002 Standards (by the way - it would be an ILLEGAL
comparison if the COMP field was not an integer):

1) The numeric field is moved to a temporary field with enough digits to
hold the  sending field. (This will *differ* depending on whether
"truncation" is or is not turned on, i.e.  if PIC S9(4) COMP can or cannot
hold a value of "10000" most compilers have one option that allows this and
one that does not).

2) In this move the sign is "thrown away" (see the rules for MOVE of a
numeric field to an alphanumeric field)

3) the class/category of this "temporary receiving field" is that of the
field to which the comparison is to be made.

4) The comparison is then made following the rules of comparison of
alphanumeric fields.  Therefore, (for example - assuming ANSI truncation is
in effect)

   05  Num1  Pic S9(04)  Comp  Value 1.
   05  AlphaNum1  Pic X(04)  Value "0001".
   05  AlphaNum2  Pic X(05)  Value "00001". 
   05  AlphaNum3  Pic X(05)  Value " 0001"

Comparison between Num1 and Alphanum1 and Alphanum3 will "pass" while the
comparison with AlphaNum2 will fail.  HOWEVER, if "non-Standard" truncation
were to be turned on, then the comparison with AlphaNum2 would pass and the
comparisons with Alphanum1 and Alphanum3 would fail.

If Num1 were defined "Pic S9(02)  Comp" (or Binary) then (for Micro Focus
with NOIBMCOMP - and any other compiler supporting one byte binary fields)
then the "temporary" field would be either 2 or 3 integers/bytes long
depending on the TRUNCATION option in effect at compile time.

> -----Original Message-----
> From: address@hidden 
> [mailto:address@hidden On 
> Behalf Of Thomas Biehler
> Sent: Friday, May 07, 2004 9:01 AM
> To: address@hidden
> Cc: Keisuke Nishida
> Subject: [open-cobol-list] possibly bug: Compare: numeric 
> (USAGE COMP ...) with alphanumeric
> 
> hi all,
> 
> i have attached a testprogram "TESTCOMPARE.cob"  (ANSI 1985!)
> which shows the problematic case of comparison:
> 
>     PIC S9(4) COMP   =    PIC X(4)
>    
>     (numeric field with a small value => 1 =  "0001")
> 
> There are references to the ANSI 1985 / ISO  2002 standard inside.
> 
> None of my compiler give a warning or error at compiling stage!
> Instead the runtime behavior is different!  :-(
> 
> I have compiled it with Micro Focus Compiler with the following flags:
> 
>    cob  -CANS85 -CFLAG=ANS85 -CWARNING=3 TESTCOMPARE.cob
> 
> No warnings and no ANSI-FLAGS at all in the compiler-output!
> (==> The same behavior with BULL GCOS7 Compiler!)
> 
> Runtime-Results:
> =====================================================
> 
> with Micro-Focus Compiler (= same results with GCOS 7000 Compiler!)
> ===================================================
> #> cobrun TESTCOMPARE.int
> COMPARE:  NUM-DISPLAY = X   SUCCESSFULL
> COMPARE:  NUM-COMP = X  SUCCESSFULL
> COMPARE:  NUM-DISPLAY => NUM-FIELD-X = X  SUCCESSFULL
> COMPARE:  NUM-COMP => NUM-FIELD-X = X  SUCCESSFULL
> 
> 
> with open-cobol  (cobc -v -Wall  --> no warnings! )
> ===================================================
> #> ./TESTCOMPARE    
> COMPARE:  NUM-DISPLAY = X   SUCCESSFULL
> COMPARE:  NUM-COMP = X  FAILED!
> COMPARE:  NUM-DISPLAY => NUM-FIELD-X = X  SUCCESSFULL
> COMPARE:  NUM-COMP => NUM-FIELD-X = X  SUCCESSFULL
> 
> 
> with tinycobol:  (htcobol -F --> no warnings!)
> ===================================================
> #> ./TESTCOMPARE
> COMPARE:  NUM-DISPLAY = X   SUCCESSFULL
> COMPARE:  NUM-COMP = X  FAILED!
> COMPARE:  NUM-DISPLAY => NUM-FIELD-X = X  SUCCESSFULL
> COMPARE:  NUM-COMP => NUM-FIELD-X = X  FAILED!
> 
> 
> If you have another compiler  (IBM , Accu-Cobol, Fujitsu ...) , 
> could you please compile it (with maximal ANSI-Flagging, "all 
> warnings") 
> and send the results  (warning, errors , output from running)
> to this mailing-list.   
> 
> Im also very interested in what your meaning is about 
> the problematic compare. 
> (Allowed or forbidden from standard ?)
> 
> What is the standard conform behavior in ANSI 1985?
> (ISO/IEC 2002 is clear !  (= simplified standard text!))
> 
> Is this a weakness in the standard ANSI 1985 standard ? 
>    OR
> a BUG in:
>       1. open-cobol , tiny-cobol ...
>       2. Micro Focus, BULL GCOS7 Compiler ...
> 
> My propose for changing open-cobol  is :
> (after evaluate your results / meanings !)
> -  give out a warning/error in ANSI 1985 mode
>    (at least a warning if it ANSI-conform, error if not ANSI-conform!)
> -  give out a sytnax error in ISO 2002 mode
> 
> Thanks and bye!
> 
> Thomas
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]