|
From: | Tim Nixon |
Subject: | [open-cobol-list] EVALUATE NULL issue |
Date: | Wed Nov 24 07:31:27 2004 |
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 |
[Prev in Thread] | Current Thread | [Next in Thread] |