Hi Folks. It's me again.
Some programming languages such as C sharp for example, support
software engineering principles such as detection of attempts
to use uninitialized variables, and ensure programs with unsafe
code must have appropriate permission to run. So, I tested my
Net Express COBOL compiler on these basic programming principles.
I moved an alphabetic string variable to a numeric variable.
the compiler did not raise a flag. It simply compiled the code,
produced an executable program and ran it. Here are my questions:
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
2). Do other programming languages compilers raise a red flag when
an alphabetic string is moved to a numeric variable?
3). Why compilers are not designed to ensure the importance of
programmers productivity and to safe guard against such
flagrant, serious and naked software bugs?
Your feedback is very much appreciated.
COBOL - the elephant that can stand on its trunk...--- Synchronet 3.20a-Linux NewsLink 1.114
On Mon, 14 May 2018 08:09:35 -0700 (PDT), Kellie Fitton <KELLIEFITTON@yahoo.com> wrote:
Hi Folks. It's me again.
Some programming languages such as C sharp for example, support
software engineering principles such as detection of attempts
to use uninitialized variables, and ensure programs with unsafe
code must have appropriate permission to run. So, I tested my
Net Express COBOL compiler on these basic programming principles.
I moved an alphabetic string variable to a numeric variable.
the compiler did not raise a flag. It simply compiled the code,
produced an executable program and ran it. Here are my questions:
Which compiler? I am fairly certain that the IBM compilers would flag
a PIC X to PIC 9 MOVE and probably fail the compilation. I don't have
a system available to me to verify this.
Clark Morris
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
2). Do other programming languages compilers raise a red flag when
an alphabetic string is moved to a numeric variable?
3). Why compilers are not designed to ensure the importance of
programmers productivity and to safe guard against such
flagrant, serious and naked software bugs?
Your feedback is very much appreciated.
COBOL - the elephant that can stand on its trunk...
Hi Folks. It's me again.
Some programming languages such as C sharp for example, support
software engineering principles such as detection of attempts
to use uninitialized variables, and ensure programs with unsafe
code must have appropriate permission to run. So, I tested my
Net Express COBOL compiler on these basic programming principles.
I moved an alphabetic string variable to a numeric variable.
the compiler did not raise a flag. It simply compiled the code,
produced an executable program and ran it. Here are my questions:
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
2). Do other programming languages compilers raise a red flag when
an alphabetic string is moved to a numeric variable?
3). Why compilers are not designed to ensure the importance of
programmers productivity and to safe guard against such
flagrant, serious and naked software bugs?
Your feedback is very much appreciated.
Using Micro Focus COBOL 3.2.50 with ANS85 flagging in effect.
-----
1$set ans85 flag"ans85" flagas"s"
2 identification division.
3 program-id. alpha1.
4 data division.
5 working-storage section.
6 1 a pic x(4).
7 1 n pic 9(4).
8 procedure division.
9 begin.
10 move "1234" to a
11 move "1234" to n
12 display a space n
13 move "abcd" to a
14 move "abcd" to n
*1026-E********************* ( 0)** ** Source literal is non-numeric - substituting zero
15 display a space n
16 stop run
17 .
18 end program alpha1.
-----
'alpha1' does not compile because the compiler caught the error.
-----
19
20 identification division.
21 program-id. alpha2.
22 data division.
23 working-storage section.
24 1 a pic x(4).
25 1 n pic 9(4).
26 procedure division.
27 begin.
28 move "1234" to a
29 move a to n
30 display a space n
31 move "abcd" to a
32 move a to n
33 display a space n
34 stop run
35 .
36 end program alpha2.
-----
1234 1234
ALPHA2 Segment RT : Error 163 at COBOL PC 0054
Description : Illegal character in numeric field (Error 163)
'alpha 2' failed because the programmer did not catch the error!
-----
37
38 identification division.
39 program-id. alpha3.
40 data division.
41 working-storage section.
42 1 a pic x(4).
43 1 n pic 9(4).
44 procedure division.
45 begin.
46 move "1234" to a
47 move a to n
48 display a space n
49 move "abcd" to a
50 if a is numeric
51 move a to n
52 else
53 display "a is not numeric: " a
54 end-if
55 display a space n
56 stop run
57 .
58 end program alpha3.
-----
1234 1234
a is not numeric: abcd
abcd 1234
'alpha3' ran because the programmer caught the error and did not
try to store the illegal characters in 'n'!
-----
[snip]Using Micro Focus COBOL 3.2.50 with ANS85 flagging in effect.
-----
1$set ans85 flag"ans85" flagas"s"
[snip]20 identification division.
21 program-id. alpha2.
22 data division.
23 working-storage section.
24 1 a pic x(4).
25 1 n pic 9(4).
26 procedure division.
27 begin.
28 move "1234" to a
29 move a to n
30 display a space n
31 move "abcd" to a
32 move a to n
33 display a space n
34 stop run
35 .
36 end program alpha2.
-----
1234 1234
ALPHA2 Segment RT : Error 163 at COBOL PC 0054
Description : Illegal character in numeric field (Error 163)
'alpha 2' failed because the programmer did not catch the error!
-----
Rick,
Thanks for your feedback.
My code is using the compiler directives $set ans85 flagas"s" but the compiler is not flagging the invalid mismatch move. When I add the
directive flag"ans85" to match your code, the compiler gives me tons
of errors and red XXX flags. My NetExpress does not like flag"ans85".
The COBOL compiler should flag this error by default in case the
programmer mistakenly references the wrong variable, this is just
a simple safety net to guard against unintentional oversight.
Hi Folks. It's me again.
Some programming languages such as C sharp for example, support
software engineering principles such as detection of attempts
to use uninitialized variables, and ensure programs with unsafe
code must have appropriate permission to run. So, I tested my
Net Express COBOL compiler on these basic programming principles.
I moved an alphabetic string variable to a numeric variable.
the compiler did not raise a flag. It simply compiled the code,
produced an executable program and ran it. Here are my questions:
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
2). Do other programming languages compilers raise a red flag when
an alphabetic string is moved to a numeric variable?
3). Why compilers are not designed to ensure the importance of
programmers productivity and to safe guard against such
flagrant, serious and naked software bugs?
Your feedback is very much appreciated.
COBOL - the elephant that can stand on its trunk...
Hi Folks. It's me again.
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
2). Do other programming languages compilers raise a red flag when
an alphabetic string is moved to a numeric variable?
3). Why compilers are not designed to ensure the importance of
programmers productivity and to safe guard against such
flagrant, serious and naked software bugs?
Your feedback is very much appreciated.
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
2). Do other programming languages compilers raise a red flag when
an alphabetic string is moved to a numeric variable?
3). Why compilers are not designed to ensure the importance of
programmers productivity and to safe guard against such
flagrant, serious and naked software bugs?
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
On Tuesday, May 15, 2018 at 3:09:36 AM UTC+12, Kellie Fitton wrote:
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
Alphabetic is 'PIC A' and only allows the alphabet. Alphanumeric is 'PIC X' and allows the full character set including numeric.
Which were you actually testing ?
In fact it can be quite useful to 'de-edit' an alphanumeric that only contains numeric characters, spaces, and full stops into a numeric field. Various compilers have allowed this, usually depending on compiler options.
When I add the
directive flag"ans85" to match your code, the compiler gives me tons
of errors and red XXX flags. My NetExpress does not like flag"ans85".
The COBOL compiler should flag this error by default in case the
programmer mistakenly references the wrong variable, this is just
a simple safety net to guard against unintentional oversight.
When I add the
directive flag"ans85" to match your code, the compiler gives me tons
of errors and red XXX flags. My NetExpress does not like flag"ans85".
The COBOL compiler should flag this error by default in case the
programmer mistakenly references the wrong variable, this is just
a simple safety net to guard against unintentional oversight.
So 'the COBOL compiler' should, by default, do things that your NetExpress does not like?
DD
When I add the
directive flag"ans85" to match your code, the compiler gives me tons
of errors and red XXX flags. My NetExpress does not like flag"ans85".
The COBOL compiler should flag this error by default in case the
programmer mistakenly references the wrong variable, this is just
a simple safety net to guard against unintentional oversight.
So 'the COBOL compiler' should, by default, do things that your NetExpress >> does not like?
DD
Moving an alphabetic variable to a numeric binary variable is an illegal
move in COBOL and should be flagged by the compiler.
This is unsafe code
that will cause errors during run-time and will have unpredictable
behavior. This is like saying compute (1000 + ABC), where ABC is not
a numeric variable in the working storage area, ABC is just a string.
Mighty COBOL is not C language or C++. :-)
When I add the
directive flag"ans85" to match your code, the compiler gives me tons
of errors and red XXX flags. My NetExpress does not like flag"ans85".
The COBOL compiler should flag this error by default in case the
programmer mistakenly references the wrong variable, this is just
a simple safety net to guard against unintentional oversight.
So 'the COBOL compiler' should, by default, do things that your NetExpress >> does not like?
DD
Moving an alphabetic variable to a numeric binary variable is an illegal
move in COBOL and should be flagged by the compiler.
This is unsafe code
that will cause errors during run-time and will have unpredictable
behavior.
This is like saying compute (1000 + ABC), where ABC is not
a numeric variable in the working storage area, ABC is just a string.
Mighty COBOL is not C language or C++. :-)
In article <cde27dbd-b1dc-49bb-8923-91d4b9bc7e0e@googlegroups.com>,
Kellie Fitton <KELLIEFITTON@yahoo.com> wrote:
(snip)
Moving an alphabetic variable to a numeric binary variable is an illegal
move in COBOL and should be flagged by the compiler.
As demonstrated, it will be flagged as such when the compiler defaults are set as such.
This is unsafe code
that will cause errors during run-time and will have unpredictable
behavior. This is like saying compute (1000 + ABC), where ABC is not
a numeric variable in the working storage area, ABC is just a string.
Anyone who codes an arithmetic operation that is not predicated on fields passing an IF NUMERIC test deserves to be on the weekend third-shift call roster permanently.
It used to be taught 'most of your code should consist of edits to make
sure your data are clean'. Has the assumption that 'all data are filthy' changed?
Mighty COBOL is not C language or C++. :-)
Mighty hammer is not tall-standing screwdriver or lively torque-wrench; different tools are used for different tasks.
DD
Which compiler? I am fairly certain that the IBM compilers would flag
a PIC X to PIC 9 MOVE and probably fail the compilation. I don't have
a system available to me to verify this.
Clark Morris
I just tested this on IBM COBOL FOR VSE/ESA 1.1.1
The compiler does not flag the move of PIC X to PIC 9. Here is a sample output I cobbled together to summarize what happens in a couple of cases:
SOURCE-FIELD 12345
DEST-FIELD 12345
SOURCE-FIELD ABCDE
DEST-FIELD ABCD5
Here is the code (at least relevant bits):
WORKING-STORAGE SECTION.
01 FILLER.
05 SOURCE-FIELD PIC X(5).
05 DEST-FIELD PIC 9(5).
PROCEDURE DIVISION.
0000-MAINLINE.
MOVE '12345' TO SOURCE-FIELD
MOVE SOURCE-FIELD TO DEST-FIELD
DISPLAY 'SOURCE-FIELD ' SOURCE-FIELD
DISPLAY ' DEST-FIELD ' DEST-FIELD
MOVE 'ABCDE' TO SOURCE-FIELD
MOVE SOURCE-FIELD TO DEST-FIELD
DISPLAY 'SOURCE-FIELD ' SOURCE-FIELD
DISPLAY ' DEST-FIELD ' DEST-FIELD
.
9000-END.
STOP RUN
.
I think the COBOL manuals explicitly state what happens in these mixed situations and indeed a LOT of old code is written to depend on that specific sort of behaviour...
Moving an alphabetic variable to a numeric binary variable is an illegal move in COBOL and should be flagged by the compiler.
I believe it IS "flagged by the compiler".
Did you check what level the target field is? (see below...)
1. I have never used a COBOL compiler (and I have used them for IBM, Burroughs, NCR, Honeywell, ICL, CDC, and PCs (both Micro Focus and
Fujitsu), which did NOT flag a move from alphabetic to numeric as
illegal. (Maybe I was lucky and every place I worked had the right
compiler options in place, but I don't think so...)
3. I was amazed that people expected a PIC X source field moving to a numeric target to be flagged as illegal. Why would it be? The source is expected to be alphaNUMERIC. Some platforms will crash with a data
exception at runtime (the famous S0c7 on IBM mainframes) if you do this
move and the contents of the source are NOT acceptably numeric, but it should not be flagged as an error at compile time. (Nevertheless, I
wouldn't do this move myself...) Neither would I ever attempt to
"de-edit" an edited field...just because you CAN do something, doesn't
mean it is always wise to do so...
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
I just tested this on IBM COBOL FOR VSE/ESA 1.1.1
The compiler does not flag the move of PIC X to PIC 9. Here is a sample
output I cobbled together to summarize what happens in a couple of cases:
SOURCE-FIELD 12345
DEST-FIELD 12345
SOURCE-FIELD ABCDE
DEST-FIELD ABCD5
Here is the code (at least relevant bits):
WORKING-STORAGE SECTION.
01 FILLER.
05 SOURCE-FIELD PIC X(5).
05 DEST-FIELD PIC 9(5).
PROCEDURE DIVISION.
0000-MAINLINE.
MOVE '12345' TO SOURCE-FIELD
MOVE SOURCE-FIELD TO DEST-FIELD
DISPLAY 'SOURCE-FIELD ' SOURCE-FIELD
DISPLAY ' DEST-FIELD ' DEST-FIELD
MOVE 'ABCDE' TO SOURCE-FIELD
MOVE SOURCE-FIELD TO DEST-FIELD
DISPLAY 'SOURCE-FIELD ' SOURCE-FIELD
DISPLAY ' DEST-FIELD ' DEST-FIELD
.
9000-END.
STOP RUN
.
I think the COBOL manuals explicitly state what happens in these mixed
situations and indeed a LOT of old code is written to depend on that
specific sort of behaviour...
Hi Kerry,
Please see table # 44 below. I wonder if the IBM compiler will flag
the move if you define the variable as PIC A ?
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/IGY3LR10/6.2.24.1?SHELF=&DT=20020920180651
Moving an alphabetic variable to a numeric binary variable is an illegal >>> move in COBOL and should be flagged by the compiler.
I believe it IS "flagged by the compiler".
Did you check what level the target field is? (see below...)
Hi Pete,
I am just conducting a simple test. Moving a 01-level alphabetic variable
to a 01-level binary numeric variable.
1. I have never used a COBOL compiler (and I have used them for IBM,
Burroughs, NCR, Honeywell, ICL, CDC, and PCs (both Micro Focus and
Fujitsu), which did NOT flag a move from alphabetic to numeric as
illegal. (Maybe I was lucky and every place I worked had the right
compiler options in place, but I don't think so...)
Please see the link below from Microfocus:
https://supportline.microfocus.com/documentation/acucorpproducts/docs/v6_online_doc/gtman3/gt36122.htm
3. I was amazed that people expected a PIC X source field moving to a
numeric target to be flagged as illegal. Why would it be? The source is
expected to be alphaNUMERIC. Some platforms will crash with a data
exception at runtime (the famous S0c7 on IBM mainframes) if you do this
move and the contents of the source are NOT acceptably numeric, but it
should not be flagged as an error at compile time. (Nevertheless, I
wouldn't do this move myself...) Neither would I ever attempt to
"de-edit" an edited field...just because you CAN do something, doesn't
mean it is always wise to do so...
Please see table # 44 below from IBM:
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/IGY3LR10/6.2.24.1?SHELF=&DT=20020920180651
I just tested this on IBM COBOL FOR VSE/ESA 1.1.1
The compiler does not flag the move of PIC X to PIC 9. Here is a sample
output I cobbled together to summarize what happens in a couple of cases:
SOURCE-FIELD 12345
DEST-FIELD 12345
SOURCE-FIELD ABCDE
DEST-FIELD ABCD5
Here is the code (at least relevant bits):
WORKING-STORAGE SECTION.
01 FILLER.
05 SOURCE-FIELD PIC X(5).
05 DEST-FIELD PIC 9(5).
PROCEDURE DIVISION.
0000-MAINLINE.
MOVE '12345' TO SOURCE-FIELD
MOVE SOURCE-FIELD TO DEST-FIELD
DISPLAY 'SOURCE-FIELD ' SOURCE-FIELD
DISPLAY ' DEST-FIELD ' DEST-FIELD
MOVE 'ABCDE' TO SOURCE-FIELD
MOVE SOURCE-FIELD TO DEST-FIELD
DISPLAY 'SOURCE-FIELD ' SOURCE-FIELD
DISPLAY ' DEST-FIELD ' DEST-FIELD
.
9000-END.
STOP RUN
.
I think the COBOL manuals explicitly state what happens in these mixed
situations and indeed a LOT of old code is written to depend on that
specific sort of behaviour...
Hi Kerry,
Please see table # 44 below. I wonder if the IBM compiler will flag
the move if you define the variable as PIC A ?
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/IGY3LR10/6.2.24.1?SHELF=&DT=20020920180651
It confirms what I said above.
(Line 1 of the permitted moves table shows that a move of alpha to
numeric is illegal.)
What's your point?
Did you try changing the level number of the receiving field?
Hi Folks. It's me again.
Some programming languages such as C sharp for example, support
software engineering principles such as detection of attempts
to use uninitialized variables, and ensure programs with unsafe
code must have appropriate permission to run. So, I tested my
Net Express COBOL compiler on these basic programming principles.
I moved an alphabetic string variable to a numeric variable.
the compiler did not raise a flag. It simply compiled the code,
produced an executable program and ran it. Here are my questions:
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
2). Do other programming languages compilers raise a red flag when
an alphabetic string is moved to a numeric variable?
3). Why compilers are not designed to ensure the importance of
programmers productivity and to safe guard against such
flagrant, serious and naked software bugs?
Stop right there.
You *said* "alphabetic string" but the example you provided down-thread uses an
*alphanumeric* string.
programs written in the 60's and say running on IBM 1401 / 7094 and even
ICL (was ICT) 1900's did not complain and many of us used this to create >program tricks. Clearly such programs when moved to more modern kit would >break and so a check was put in to Cobol to ensure the risk of this
happening was reduced and/or stopped.
It can however, still happen :(
Hi Folks. It's me again.
Some programming languages such as C sharp for example, support
software engineering principles such as detection of attempts
to use uninitialized variables, and ensure programs with unsafe
code must have appropriate permission to run. So, I tested my
Net Express COBOL compiler on these basic programming principles.
I moved an alphabetic string variable to a numeric variable.
the compiler did not raise a flag. It simply compiled the code,
produced an executable program and ran it. Here are my questions:
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
2). Do other programming languages compilers raise a red flag when
an alphabetic string is moved to a numeric variable?
3). Why compilers are not designed to ensure the importance of
programmers productivity and to safe guard against such
flagrant, serious and naked software bugs?
Your feedback is very much appreciated.
COBOL - the elephant that can stand on its trunk...
Hi Folks. It's me again.
Some programming languages such as C sharp for example, support
software engineering principles such as detection of attempts
to use uninitialized variables, and ensure programs with unsafe
code must have appropriate permission to run. So, I tested my
Net Express COBOL compiler on these basic programming principles.
I moved an alphabetic string variable to a numeric variable.
the compiler did not raise a flag. It simply compiled the code,
produced an executable program and ran it. Here are my questions:
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
2). Do other programming languages compilers raise a red flag when
an alphabetic string is moved to a numeric variable?
3). Why compilers are not designed to ensure the importance of--- Synchronet 3.20a-Linux NewsLink 1.114
programmers productivity and to safe guard against such
flagrant, serious and naked software bugs?
Your feedback is very much appreciated.
On 5/14/2018 11:42 AM, Clark F Morris wrote:
On Mon, 14 May 2018 08:09:35 -0700 (PDT), Kellie Fitton
<K.....@yahoo.com> wrote:
Some programming languages such as C sharp for example, support
software engineering principles such as detection of attempts
to use uninitialized variables, and ensure programs with unsafe
code must have appropriate permission to run. So, I tested my
Net Express COBOL compiler on these basic programming principles.
I moved an alphabetic string variable to a numeric variable.
the compiler did not raise a flag. It simply compiled the code,
produced an executable program and ran it. Here are my questions:
Which compiler? I am fairly certain that the IBM compilers would flag
a PIC X to PIC 9 MOVE and probably fail the compilation. I don't have
a system available to me to verify this.
Clark Morris
1). Why the COBOL compiler does not raise a red flag when you move
an alphabetic string to a numeric variable?
2). Do other programming languages compilers raise a red flag when
an alphabetic string is moved to a numeric variable?
3). Why compilers are not designed to ensure the importance of
programmers productivity and to safe guard against such
flagrant, serious and naked software bugs?
Your feedback is very much appreciated.
COBOL - the elephant that can stand on its trunk...
I just tested this on IBM COBOL FOR VSE/ESA 1.1.1
The compiler does not flag the move of PIC X to PIC 9. Here is a sample output I cobbled together to summarize what happens in a couple of cases:
SOURCE-FIELD 12345
DEST-FIELD 12345
SOURCE-FIELD ABCDE
DEST-FIELD ABCD5
Here is the code (at least relevant bits):
WORKING-STORAGE SECTION.
01 FILLER.
05 SOURCE-FIELD PIC X(5).
05 DEST-FIELD PIC 9(5).
PROCEDURE DIVISION.
0000-MAINLINE.
MOVE '12345' TO SOURCE-FIELD
MOVE SOURCE-FIELD TO DEST-FIELD
DISPLAY 'SOURCE-FIELD ' SOURCE-FIELD
DISPLAY ' DEST-FIELD ' DEST-FIELD
MOVE 'ABCDE' TO SOURCE-FIELD
MOVE SOURCE-FIELD TO DEST-FIELD
DISPLAY 'SOURCE-FIELD ' SOURCE-FIELD
DISPLAY ' DEST-FIELD ' DEST-FIELD
.
9000-END.
STOP RUN
.
I think the COBOL manuals explicitly state what happens in these mixed situations and indeed a LOT of old code is written to depend on that specific sort of behaviour...
SOURCE-FIELD 12345
DEST-FIELD 12345
SOURCE-FIELD ABCDE
DEST-FIELD ABCD5
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,030 |
Nodes: | 10 (0 / 10) |
Uptime: | 41:27:31 |
Calls: | 13,347 |
Calls today: | 1 |
Files: | 186,574 |
D/L today: |
4,089 files (933M bytes) |
Messages: | 3,358,104 |