[comp.sys.amiga] Abuse of 'C'

peter@sugar.UUCP (Peter da Silva) (06/30/88)

In article <6941@cup.portal.com>, doug-merritt@cup.portal.com writes:
> >#define ctrl(c) \
> >    (((c)<' ')?("^"[1]=(c)+'@',""[-2]):(((c)>'~')?"^?":(""[0]=(c),""[-1])))
> 
> Thank you for the appreciation :-), that monstrosity was my invention.

You sure you're not Ken Arnold in disguise? :->

> Ken was saying how you couldn't do it as a macro without side-effects
> nor a global variable, and I just had to come up with a counter example.

Of course, it's going to be pretty aweful if you do something like:

	ctrl(av[i][j++]);

How about:

#define ctrl(c) \
	&("^@\0\0\0^B\0\0\0^C\0\0\0...M-^?\0"[(c)*5])
			   ^^^-- Imagine a whole bunch of stuff here.

With ANSI string constant sharing it isn't even horrible, if you only
use it in one source file... You could use string concatenation to make
it readable...

	&("^@\0\0\0...^_\0\0\0"
	" \0\0\0\0...?\0\0\0\0"
	"@\0\0\0\0..._\0\0\0\0"
	"`\0\0\0\0...^?\0\0\0"
	"M-^@\0...M-^_\0"
	"M- \0\0...M-?\0\0"
	"M-@\0\0...M-_\0\0"
	"M-`\0\0...M-^?\0"[(c)*5])
-- 
-- `-_-' Peter (have you hugged your wolf today?) da Silva.
--   U   Mail to ...!uunet!sugar!peter, flames to /dev/null.
-- "A foolish consistancy is the hobgoblin of little minds".

gay%CLSEPF51.BITNET@cunyvm.cuny.edu (David Gay) (07/01/88)

In article <6941@cup.portal.com>, doug-merritt@cup.portal.com writes:

> >#define ctrl(c) \
> >    (((c)<' ')?("^"[1]=(c)+'@',""[-2]):(((c)>'~')?"^?":(""[0]=(c),""[-1])))
Shouldn't this be
#define ctrl(c) \
    (((c)<' ')?("^"[1]=(c)+'@',"" - 2):(((c)>'~')?"^?":(""[0]=(c),"" - 1)))
                                 ^^^^                               ^^^^

>
> Thank you for the appreciation :-), that monstrosity was my invention.

Well, it was at least worth a good laugh ...

---
David Gay                           Studying Computer Science at the EPFL,
                                    Ecole Polytechnique Federale de Lausanne,
How do you invent a signature ?     Switzerland.

GAY@ELDE.EPFL.CH, or
GAY@CLSEPF51.bitnet (till August)