

This case cannot be detemined at compile time. Output: prompt$ cobc -xj b -cb_conf=complex-odo:yes -cb_conf=binary-size:1-8 display "Complex ODO at 1 and 5 : " length ( group-item ) goback. display "Size of:" display "BINARY-CHAR : " bc-len display " bc-len constant : " byte-length ( bc-len ) display "FLOAT-DECIMAL-34 : " fd-34-len display " fd-34-len constant : " byte-length ( fd-34-len ) display "PIC X(13) field : " length of fixed-character display "PIC N(13) field : " length of fixed-national display "PIC S9(5) field : " length of fixed-nine display "PIC S9(5) sign separate : " length of fixed-separate display "PIC S9(5) COMP-5 : " length of computable-field display "ALPHANUMERIC-EDITED : " length ( formatted-field ) display "BINARY-DOUBLE field : " byte-length ( binary-field ) display "POINTER field : " length ( pointer-item ) > IF P64 IS SET display " sizeof(char *) > 4" > ELSE display " sizeof(char *) = 4" > END-IF display "Complex ODO at 2 and 4 : " length of group-item set odo down by 1. 05 second-inner pic x occurs 0 to 5 times depending on odo-2. 05 first-inner pic x occurs 0 to 3 times depending on odo. 77 computable-field pic s9(5) usage computational-5. 77 fixed-separate pic s9(5) sign trailing separate. 01 fd-34-len constant as length of float-decimal-34. 01 bc-len constant as length of binary-char. Provide some way of determining this at compile time, as with the Compilerĭirecting Facility >IF P64 IS SET, shown here. POINTER data is one of the few platform dependent fields, and most compilers Same for BINARY-CHAR (1), BINARY-SHORT (2), BINARY-DOUBLE (8), by spec. In COBOL a BINARY-LONG is 32 bits, by definition, and does not change from platform to platform. Time when compile time sizing is not determinable. There are run-time functions for LENGTH, BYTE-LENGTH, and a common extensionįor a LENGTH OF phrase that works at both compile time if possible and at run

Group items are mostly determined by the data definition, with some varianceĭue to binary sizing and programmer controlled OCCURS DEPENDING ON run time Some native architecture sizing can be controlled by configuration or will be #include std :: size_t size = sizeof ( 3 * 6 + 7.5 ) COBOL ĬOBOL is by and large a fixed length system, most data types have a size The sizes reported do not include the 2 bytes to store the variable name. To get the size of the variable, determine the type of the last variable used. String variables use 3 bytes: 1 byte for the length of the string, 2 bytes for the pointer to the string in memory, and have 0's in the remaining 2 bytes.įunctions use 2 bytes for the pointer to the function definition in the program, 2 bytes for the pointer to the argument, a 1 byte copy of the first character of the function definition, and 7 bytes to store the argument variable. Integer variables use 2 bytes for the value, and have 0's in the remaining 3 bytes. Real variables use all 5 bytes for the value: a 1 byte exponent, and a 4 byte mantissa. Simple (non-array) real, integer, or string variables use 7 bytes including the 2 bytes for the variable name.

Note that when used with a string, LEN reports the length of the string, not its size in memory.īASIC typically stores information about the string separately from the string itself, usually immediately before the string itself in memory (but some implementations may store such information elsewhere).
