[Coco] "C" Compiler C_PREP19 errors or mine?
Michael Furman
n6il at ocs.net
Sat May 21 13:00:36 EDT 2011
I just cracked open my copy of "C: A Reference Manual, Fourth Edition; 1995 to help answer your question. This has been the best C reference ever for me, it answers almost any question I have ever had.
Section 2.7.5 explains escape characters. The bnf-style syntax is as follows. The book claims that this bnf describes ISO Standard C:
escape-character:
\ escape-code
escape-code:
character-escape-code
octal-escape-code
hex-escape-code
character-escape-code: one of
n t b r f
v \ ' "
a ?
octal-escape-code:
octal-digit
octal-digit octal-digit
octal-digit octal-digit octal-digit
hex-escape-code:
x hex-digit
hex-escape-code hex-digit
octal-digit: one of
0 1 2 3 4 5 6 7
hex-digit: one of
0 1 2 3 4 5 6 7 8 9
A B C D E F a b c d e f
That's it. It goes on to explain:
"If the character following the backslash is neither an octal digit, the letter x, nor one of the character escape codes listed above, the result is undefined (In traditional C, the backslash was ignored.) In ISO C, all lowercase letters following the backslash are reserved for future language extensions. Uppercase letters may be used for implementation specific extensions."
According to this definition, there is no way to have decimal escape codes in C.
Further I did the following experiment using bash shell. This follows everything stated above:
$ printf "\x1BM\x1Bl\d010\x1BQ\d090" | hexdump -C
00000000 1b 4d 1b 6c 5c 64 30 31 30 1b 51 5c 64 30 39 30 |.M.l\d010.Q\d090|
00000010
I hope this answers your question.
On May 21, 2011, at 7:59 AM, Stephen H. Fischer wrote:
> Hi,
>
> Please read this E-mail using a monospaced font!
>
> In trying to build a new copy of my program I discovered two things that puzzle me both related to C_PREP19.
>
> I am using CPREP19.lzh from Gene as well as CC252.lzh.
>
> http://gene.homelinux.net:85/gene/Genes-os9-stf/
>
> ------------------------------------------------
> The first item are the Syntax errors reported for the
>
> "fputs("\x1BM\x1Bl\d010\x1BQ\d090",fcb);" lines.
>
> This sends control codes to an Epson printer.
>
> Twenty years ago this was accepted just fine.
>
> I checked the CoCo OS-9 "C" Compiler manual and they are correct.
>
> They are NOT correct for ANSI "C" AFAIK.
>
> C_PREP is an ANSI standard C preprocessor. It can completely replace
> Microware's c.prep. It contains all of the features of c.prep plus some
> extras. It follows the grammar set out in the ANSI C standard by the X3J11
> committee.
>
> The unofficial ANSI "C" document I looked at did not give an option for decimal and in any case the CoCo OS-9 "C" Compiler requires the format I used. (I converted to HEX.)
>
> I think that this checking is NOT proper to be done in C_PREP without running CC with the
>
> "-A Run ansifront for ANSI-C processing." option selected.
>
> ------------------------------------------------
> The second item is the suggested use of __DATE__, __TIME__ and __FILE__ taken right from the "cprep19.doc" file.
>
> To me these need to substituted into strings, but they are not.
>
> "__DATE__, __TIME__ and __FILE__ " would be useful.
>
> ------------------------------------------------
>
> /*----------- testcp19 -------------------*/
> #include <stdio.h>
> #include <ctype.h>
>
>
> /* Globals */
> FILE *fcb;
> char ch3;
> int num;
>
> main(argc,argv)
> int argc;
> char *argv[];
> {
>
> fcb=fopen("/P","w");
>
> fcb->_flag |= _RBF; /* stop output editing */
>
> /* Switch to stdout from /P */
> fcb = stdout;
>
>
> fputs("\x1BM\x1Bl\d010\x1BQ\d090",fcb);
>
> fputs("\x1BP\x1Bl\d004\x1BQ\d084",fcb);
>
> fprintf(stderr,"Current file name is: %s\n",__FILE__);
> fprintf(stderr,"Compile date is: %s\n",__DATE__);
> fprintf(stderr,"Compile time: %s\n",__TIME__);
> }
>
> /*----------- testcp19 -------------------*/
>
> ------------------------------------------------
>
> *** "testcp19.c" <Line #23> Syntax error - Illegal escape sequence ***
> fputs("\x1BM\x1Bl\d010\x1BQ\d090",fcb);
> ^
>
> *** "testcp19.c" <Line #23> Syntax error - Illegal escape sequence ***
> fputs("\x1BM\x1Bl\d010\x1BQ\d090",fcb);
> ^
>
> *** "testcp19.c" <Line #23> Syntax error - Illegal escape sequence ***
> fputs ( x1BM\x1Bl\d010\x1BQ\d090",fcb);
> ^
>
> *** "testcp19.c" <Line #23> Syntax error - Illegal escape sequence ***
> fputs ( x1BM\x1Bl\d010\x1BQ\d090",fcb);
> ^
>
> *** "testcp19.c" <Line #25> Syntax error - Illegal escape sequence ***
> fputs("\x1BP\x1Bl\d004\x1BQ\d084",fcb);
> ^
>
> *** "testcp19.c" <Line #25> Syntax error - Illegal escape sequence ***
> fputs("\x1BP\x1Bl\d004\x1BQ\d084",fcb);
> ^
>
> *** "testcp19.c" <Line #25> Syntax error - Illegal escape sequence ***
> fputs ( x1BP\x1Bl\d004\x1BQ\d084",fcb);
> ^
>
> *** "testcp19.c" <Line #25> Syntax error - Illegal escape sequence ***
> fputs ( x1BP\x1Bl\d004\x1BQ\d084",fcb);
> ^
> testcp19.c : line 28 **** undeclared variable ****
> fprintf ( ( & _iob [ 2 ] ) , "Current file name is: %s\n" , testcp19.c ) ;
> ^
> testcp19.c : line 28 **** struct member required ****
> fprintf ( ( & _iob [ 2 ] ) , "Current file name is: %s\n" , testcp19.c ) ;
> ^
> testcp19.c : line 28 **** undeclared variable ****
> fprintf ( ( & _iob [ 2 ] ) , "Current file name is: %s\n" , testcp19.c ) ;
> ^
> testcp19.c : line 29 **** ) expected ****
> fprintf ( ( & _iob [ 2 ] ) , "Compile date is: %s\n" , May 21 1911 ) ;
> ^
> testcp19.c : line 29 **** undeclared variable ****
> fprintf ( ( & _iob [ 2 ] ) , "Compile date is: %s\n" , May 21 1911 ) ;
> ^
> testcp19.c : line 29 **** ; expected ****
> fprintf ( ( & _iob [ 2 ] ) , "Compile date is: %s\n" , May 21 1911 ) ;
> ^
> testcp19.c : line 29 **** ; expected ****
> fprintf ( ( & _iob [ 2 ] ) , "Compile date is: %s\n" , May 21 1911 ) ;
> ^
> testcp19.c : line 29 **** ; expected ****
> fprintf ( ( & _iob [ 2 ] ) , "Compile date is: %s\n" , May 21 1911 ) ;
> ^
> testcp19.c : line 29 **** syntax error ****
> fprintf ( ( & _iob [ 2 ] ) , "Compile date is: %s\n" , May 21 1911 ) ;
> ^
> testcp19.c : line 30 **** ) expected ****
> fprintf ( ( & _iob [ 2 ] ) , "Compile time: %s\n" , 07:04:30 ) ;
> ^
> testcp19.c : line 30 **** ; expected ****
> fprintf ( ( & _iob [ 2 ] ) , "Compile time: %s\n" , 07:04:30 ) ;
> ^
> testcp19.c : line 30 **** syntax error ****
> fprintf ( ( & _iob [ 2 ] ) , "Compile time: %s\n" , 07:04:30 ) ;
> ^
> errors in compilation : 12
>
> cc version 2.5.2
> 'testcp19.c'
> c_prep : testcp19.c
> c.pass1: /DD/TMP/ctmp.4.m -o=/DD/TMP/ctmp.4.a
>
> ------------------------------------------------
>
> TIA
>
> SHF
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
More information about the Coco
mailing list