From: deu439 <de...@az...> - 2009-01-13 19:43:43
|
David Essex wrote: > Assuming you mean C structures, '01' levels can be consided to provide > equivalent functionality (with the C 'pragma pack(1)' directive). Thanks, but I _didnt_ mean structures. Typedef; can be used for define new data type/structures. So I can declare new variable/struct with defined aligment. Like this: ################# //define data type "NAME" typedef struct{ int a; int b; }NAME; main(){ //declare struct //with "NAME" aligment NAME declared_struct; } ################# Sorry whether it's too intuitive. I found documentation of LINKAGE section in IBM web. Well I can define the data structure in LINKAGE section and next rewrite address of this structure to any other address, but it's too intricately. First I must acquire lenght of structure, allocate memory, until I can rewrite the address. Any other ideas, how can I do it in tiny cobol? ------------------- de...@in... Czech Republic |
From: David E. <de...@us...> - 2009-01-14 12:53:51
|
deu439 wrote: > Thanks, but I _didnt_ mean structures. > > Typedef; can be used for define new data type/structures. > So I can declare new variable/struct with defined aligment. > > Like this: > > //define data type "NAME" > typedef struct{ > int a; > int b; > }NAME; > > main(){ > //declare struct > //with "NAME" aligment > NAME declared_struct; > } > > Sorry whether it's too intuitive. AFAIK, COBOL (85 standard) does not differentiate between a declaration and definition (memory allocation). Meaning it does both in one step. However you can use qualification to achieve a similar effect. Example: ... 01 NAME-A. 05 INT-A PIC S9(8). 05 INT-B PIC S9(8). 01 NAME-B. 05 INT-A PIC S9(8). 05 INT-B PIC S9(8). ... MOVE INT-B OF NAME-A TO INT-A OF NAME-B. > I found documentation of LINKAGE section in IBM web. > Well I can define the data structure in LINKAGE section and next rewrite > address of this structure to any other address, but it's too > intricately. > First I must acquire lenght of structure, allocate memory, until I can > rewrite the address. > > Any other ideas, how can I do it in tiny cobol? I don't understand what you are trying to accomplish. In any case TC does support the following. Pointers to a limited extent. Example: ... 01 NAME-P POINTER. ... SET idetifier-1 TO ADDRESS OF idetifier-2. Length of identifiers. Example: ... 01 INT-A PIC S9(4). ... MOVE LENGTH OF idetifier-1 TO idetifier-2 Dynamic memory allocation is not supported in TC (COBOL 85 standard). I think it was introduced in the COBOL 2002 standard. Hope this helps. HINT: You can find some examples on how to mix COBOL/C/COBOL programs in the 'test.code' directories of the source code. |
From: Fred M. <fr...@mo...> - 2009-01-14 17:39:56
|
On Wednesday 14 January 2009 12:57, David Essex wrote: > deu439 wrote: > > Thanks, but I _didnt_ mean structures. > > > > Typedef; can be used for define new data type/structures. > > So I can declare new variable/struct with defined aligment. > > > > Like this: > > > > //define data type "NAME" > > typedef struct{ > > int a; > > int b; > > }NAME; > > > > main(){ > > //declare struct > > //with "NAME" aligment > > NAME declared_struct; > > } > > > > Sorry whether it's too intuitive. > > AFAIK, COBOL (85 standard) does not differentiate between a > declaration and definition (memory allocation). Meaning it does both > in one step. I don't understand the original question of OP, but I would like to add to your statement above. In a WORKING-STORAGE SECTION, declarations allocate memory and declare a memory layout. In a LINKAGE SECTION, declarations don't allocate memory but just declare a memory layout. The memory is in general allocated in the calling program in the WORKING-STORAGE SECTION. Example : PROGRAM-ID. A. <--- Main program. ... WORKING-STORAGE SECTION. <--- allocation and layout. 01 AREA-A-1. 03 FIELD-A-1-A PICTURE X(7). 03 FIELD-A-1-B PICTURE X(3). 01 AREA-A-2. 03 FIELD-A-2-A PICTURE X(7). 03 FIELD-A-2-B PICTURE X(3). 01 AREA-A-3. 03 FIELD-A-3-A PICTURE X(7). 03 FIELD-A-3-B PICTURE X(3). PROCEDURE DIVISION. START SECTION. P00. CALL "B" USING AREA-A-1 AREA-A-3. EOS. STOP RUN. PROGRAM-ID. B. <--- Subroutine. ... LINKAGE SECTION. <--- Only layout per 01 level. 01 AREA-B-1. 03 FIELD-B-1-A PICTURE X(7). 03 FIELD-B-1-B PICTURE X(3). 01 AREA-B-2. 03 FIELD-B-2-A PICTURE X(7). 03 FIELD-B-2-B PICTURE X(3). PROCEDURE DIVISION USING AREA-B-1 AREA-B-2. START SECTION. P00. .... EOS. EXIT PROGRAM. PLease notice that the subroutine B does not know if the arguments AREA-B-1 and AREA-B-2 are located in adjacent area's or not. The main program A knows they're NOT. Often such structures are put in copy members in order to avoid differences in declarations. But that results in another problem : VALUE clauses are (were ?) not allowed in the linkage section. -- Fred Mobach - fr...@mo... - pos...@mo... website : http://fred.mobach.nl .... In God we trust .... .. The rest we monitor .. |