Ubuntu GnuCobol货币符号为“£”会导致编译错误

时间:2019-03-03 22:07:25

标签: cobol gnucobol

在Ubuntu 18.10上使用GnuCOBOL 2.2.0。 Michael Coughlan撰写的“面向程序员的COBOL入门”一文。 直到第9章,该程序为止,GnuCOBOL一直在毫不费力地编译本书的示例:

IDENTIFICATION DIVISION.
PROGRAM-ID. Listing9-2.
AUTHOR. Michael Coughlan.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
    CURRENCY SIGN IS "£".
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Edit1    PIC £££,££9.99.

PROCEDURE DIVISION.
Begin.
    MOVE 12345.95 TO Edit1
    DISPLAY "Edit1 = " Edit1
    STOP RUN.

...尝试进行编译时引发以下错误:

~/Documents/COBOL$ cobc -x -free Listing9-2.cbl
Listing9-2.cbl: 8: error: PICTURE SYMBOL for CURRENCY must be one character long
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: 11: error: invalid PICTURE character '�'
Listing9-2.cbl: in paragraph 'Begin':
Listing9-2.cbl: 15: error: invalid MOVE statement

如果所有的£字符都替换为$,则编译成功。问题可能是GnuCOBOL不支持英镑符号吗?或者,是否需要输入一种不同于仅在键盘上按“£”的方式?

1 个答案:

答案 0 :(得分:6)

如编译器所说:

  

用于货币的图片符号必须为一个字符长

因此,在源文件中找到的£不是一个长字符-我假设您使用了UTF-8编码,而GnuCOBOL不直接支持任何多字节源编码(实际上,只要在任何地方都没有“大小溢出”。

如果可能的话,我建议将编码更改为ISO-8859-15,这是一种包含字节号的单字节编码。