[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [open-cobol-list] EVALUATE NULL issue
From: |
William M. Klein |
Subject: |
RE: [open-cobol-list] EVALUATE NULL issue |
Date: |
Wed Nov 24 12:52:19 2004 |
Does any other figurative constant work in the EVALUATE statement? I
haven't checked this out, but I don't think it should, e.g.
Evaluate Space
When alpha-num-field ...
________________________________
From: address@hidden
[mailto:address@hidden On Behalf Of Tim Nixon
Sent: Wednesday, November 24, 2004 8:26 AM
To: address@hidden
Cc: address@hidden
Subject: [open-cobol-list] EVALUATE NULL issue
EVALUATE NULL issue
The following code works:
WORKING-STORAGE SECTION.
01 NEWVAR POINTER.
PROCEDURE DIVISION.
MOVE NULL TO NEWVAR.
EVALUATE NEWVAR
WHEN NULL
DISPLAY "NEWVAR IS NULL"
WHEN OTHER
DISPLAY "NEWVAR is NOT NULL"
END-EVALUATE.
=====================================
But with the same beginning code this does not compile
EVALUATE NULL
WHEN NEWVAR
DISPLAY "NEWVAR IS NULL"
WHEN OTHER
DISPLAY "NEWVAR is NOT NULL"
END-EVALUATE.
-----------------------------------------------
The difference is that EVALUATE <var> WHEN NULL generates correct c-code,
but EVALUATE NULL WHEN <var> does not.
for the working case the generated c code line is this:
if((((*(unsigned char**)(b_6))-0) == 0))
for the non working case it's
if(((0-(*(unsigned char**)(b_6))) == 0))
the real issue is that in c its allowable to subtract a value from a
pointer, but not a pointer from a value. In other words (ADDRESS - number)
is OK, but (number - ADDRESS) is not.
------------------------------------------------
FIX: in codegen.c, output_integer() function added test case for cb_null
and wrapped output value of NULL in a typecast... rather than outputting
just a "0".
Listing: (NOTE: line numbers may not be exact)
524 static void
525 output_integer (cb_tree x)
526 {
527 switch (CB_TREE_TAG (x))
528 {
529 case CB_TAG_CONST:
530 if (x == cb_zero)
531 output ("0");
532 else
533 /*********FIX*************/
534 if(x == cb_null){
535 output (" ((unsigned char *)NULL) ");
536 }else
537 /*********END FIX*************/
538 output ("%s", CB_CONST (x)->val);
539 break;
540 case CB_TAG_INTEGER:
Tim Nixon