CTRL(X) in ANSI standard

Mark Purtill Purtill at MIT-MULTICS.ARPA
Sat May 11 11:16:19 AEST 1985


<Fnord>
> >> [use '\^X' instead of CTRL(x) or CTRL('x')]
> > As has been said before, the right way to do this is:
> >         #define   BEL       '\007'

> I was thinking mainly about programs that use curses or otherwise read
> characters one at a time and do special things with ctrl chars.  E.g.,

Actually, that's no problem.  You just say

#define UP_CHAR     '\025'
#define DOWN_CHAR   '\004'
...
    switch( c) {                        
        case UP_CHAR:
            ...
        Case DOWN_CHAR:
            ...
            ...
        }

This is actually BETTER, since you don't have magic numbers in the code.
>                                                        using
>printf("\^T%c%c", row, col) is a bit more obvious than
>printf("\024%c%c", row, col).
This brings up a real problem: if you have a magic CHARACTER, you can't
use it in a STRING.  Under ANSI C, at least you can get by with
#define MAGIC_CHAR '\024'
#define MAGIC_CHAR_STRING "\024"
and then say 
    printf( MAGIC_CHAR_STRING "%c%c", row, col) ;
but that's not really satisfactory.  (It *is* better that
    printf( "%c%c%c", MAGIC_CHAR,...) ;
or
    printf( "\666%c%c",...) ;           
tho.)  How about making a string adjacent to a character constant absorb
said character constant?  Then
    "foo" '\001' => "foo\001", and '\001' "foo" => "\001foo", 
just as in the standard, "foo" "\001" => "foo\001".  Then 
    printf( MAGIC_CHAR "%c%c",...) ;
works like one would like.

       Mark
^.-.^  Purtill at MIT-MULTICS.ARPA    **Insert favorite disclaimer here**
(("))  2-032 MIT Cambrige MA 02139



More information about the Comp.lang.c mailing list