gnucobol-users
[Top][All Lists]
Advanced

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

Re: [open-cobol-list] CVS Update 20061015


From: Roger While
Subject: Re: [open-cobol-list] CVS Update 20061015
Date: Wed, 18 Oct 2006 09:58:34 +0200

Yep, I am talking through the top of my hat :-(
Of course, this is valid.
Sergey's fixes are not quite correct.
The change at line 623 typeck.c is correct.
     if (n < 1 || n > p->occurs_max) {
The rest not.
Problem is further down in typeck.c starting at line 631 (the ODO check).
Here we should be unconditionally generating the runtime ODO and subscript check.
Further the subscript check should be passing cb_int1 and not
cb_int (p->occurs_min).
In other words I believe it should look like this (not yet tested) -

 if (CB_EXCEPTION_ENABLE (COB_EC_BOUND_SUBSCRIPT)) {
               if (p->occurs_depending) {
                        cb_tree e1, e2;

                         e1 = cb_build_funcall_4 ("cob_check_odo",
cb_build_cast_integer (p->occurs_depending), cb_int (p->occurs_min), cb_int (p->occurs_max),
                                                         cb_build_string0
((ucharptr)(cb_field (p->occurs_depending)->name)));
                          e2 = cb_build_funcall_4 ("cob_check_subscript",
cb_build_cast_integer (sub),
                                                         cb_int1,
cb_build_cast_integer (p->occurs_depending), cb_build_string0 ((ucharptr)p->name));
                           r->check = cb_list_add (r->check, e1);
                           r->check = cb_list_add (r->check, e2);
                 } else {

More later.

Roger


Not exactly. The field X can occur from four to six times. If it occurs four
times then x(1), x(2), x(3) and x(4) are all valid subscripted references.
The occurs clause simply tells how many occurences there are. The subscripts
always start at 1 and are valid through the maximum size of the table, in
this case four.  If the standard says otherwise then the standard has been
screwed up somehow or else misinterpreted  in the creation of Open COBOL.

I quote from my most recent COBOL text:
"After a variable-length table is loaded and the number of elements determined
then it can be accessed or searched just like a fixed length table."
_Structured COBOL Programming_ Shelly, Cashman, Foreman, 2000
And an older text:

"Thus, DAILY-TOTAL will have either 28, 29, 30 or 31 items depending on an
input field called DAYS-IN -MONTH...."
"Structured Programming, Fourth Edition", Stern & Stern 1985

A situation where you could only reference the last four days of the month
would be absurd.

But the program fails in both Tiny COBOL and Open COBOL as written.

The problem is more simple. Small compilers tend to be one pass compilers.
At the time of evaluating the number of occurences
the value of N has not yet been defined. If we rearrange the statements the
program compiles and executes using tiny COBOL. Of course since no value is
ever assigned to x(3) the display statement yields a blank.
Here is the rearranged code.
        IDENTIFICATION   DIVISION.
        PROGRAM-ID.      prog.
        DATA             DIVISION.
        WORKING-STORAGE  SECTION.
        01 N             PIC 9 VALUE 4.
        01 G.
            02 X           PIC X OCCURS 4 TO 6 TIMES DEPENDING ON N.
        PROCEDURE        DIVISION.
            DISPLAY X(3).
            STOP RUN.

Unfortunately Open COBOL still fails, indicating a compiler bug.

If I add the statement

            MOVE "A" TO X(3).
then the Tiny COBOL version compiles, executes, and displays the letter A.
but the Open COBOL version has two subscript errors.



> Here's what the standard says -
>
> -----
> The value of the data item referenced by data-name-1 represents
> the current number of occurrences of the subject of the entry.
> The subject of this entry has a variable number of occurrences.
> The value of integer-2 represents the maximum number of occurrences
> and the value of integer-1 represents the minimum number of occurrences.
> This does not imply that the length of the subject of the entry is
> variable, but that the number of occurrences is variable.
> At the time the subject of entry is referenced or any data item subordinate
> or superordinate to the subject of entry is referenced, the value of the
> data item referenced by data-name-1 shall fall within the bounds from
> integer-1 through integer-2.
> If the value of the data item does not fall within the specified bounds,
> the EC-BOUND-ODO exception condition is set to exist.
> The content of a data item whose occurrence number
> exceeds the value of the data item referenced by data-name-1 is undefined.
>   -----
>
> Roger
>
> >    I down loaded and built the latest release of the Open Source COBOL
> >Compiler. I would expect the following program to compile:
> >
> >
> >However, I get a compile time error stating that the subscript for X is
> >wrong.
> >
> >Bob Sherry
> >
> >-----Original Message-----
> >From: address@hidden
> >[mailto:address@hidden On Behalf Of Roger
> >While
> >Sent: Sunday, October 15, 2006 5:57 AM
> >To: address@hidden
> >Subject: [open-cobol-list] CVS Update 20061015
> >
> >CVS updated.
> >Tarball (AKA Prerelease) at :
> >http://ww.sim-basis.de/open-cobol-0.33.tar.gz
> >
> >Too many things changed to list here.
> >See the ChangeLog files in the top-level
> >and sub-directories (cobc, libcob, config, bin, tests)
> >
> >Roger





reply via email to

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