Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I love relational operators so much

3 views
Skip to first unread message

Andrey Vul

unread,
Nov 7, 2009, 8:08:32 PM11/7/09
to
C's handling of 'if' leads to a lot of room for obfuscation. All you
have to do is replace ';' with '|' for compound expressions and add
parentheses as neccessary.
if (x)
y;
else
z;
becomes
((x)&&(y))
||(z);

for compounds,
if (x)
y;z;a;b;
else
c;d;e;f;
becomes
((x) && ((y)|(z)|(a)|(b))
||((c)|(d)|(e)|(f));

C is so much fun to obfuscate. Gotta love ISO 9899.
The result is still more readable than perl, though.

Andrey Vul

unread,
Nov 7, 2009, 8:13:44 PM11/7/09
to
On Nov 7, 8:08 pm, Andrey Vul <andrey....@gmail.com> wrote:
> C's handling of 'if' leads to a lot of room for obfuscation. All you
> have to do is replace ';' with '|' for compound expressions and add
> parentheses as neccessary.
> if (x)
>  y;
> else
>  z;
> becomes
> ((x)&&(y))
> ||(z);
>
> for compounds,
> if (x)
>  y;z;a;b;
> else
>  c;d;e;f;
> becomes
> ((x) && ((y)|(z)|(a)|(b))
> ||((c)|(d)|(e)|(f));
>

Uh oh, | isn't gonna work on for- or while-loops.

Andrey Vul

unread,
Nov 7, 2009, 8:14:58 PM11/7/09
to
On Nov 7, 8:13 pm, Andrey Vul <andrey....@gmail.com> wrote:

> Uh oh, | isn't gonna work on for- or while-loops.

But it does work for pure-sequentials e.g., do{ ... }while(0), etc.

Andrey Vul

unread,
Nov 7, 2009, 8:21:20 PM11/7/09
to
On Nov 7, 8:13 pm, Andrey Vul <andrey....@gmail.com> wrote:

> Uh oh, | isn't gonna work on for- or while-loops.

and void()s

but void() => int() by changing return to return 0

Eric Sosman

unread,
Nov 8, 2009, 8:33:24 AM11/8/09
to
Andrey Vul wrote:
> C's handling of 'if' leads to a lot of room for obfuscation. All you
> have to do is replace ';' with '|' for compound expressions and add
> parentheses as neccessary.
> if (x)
> y;
> else
> z;
> becomes
> ((x)&&(y))
> ||(z);

I tried your suggestion, with `exit(0)' for `z', and
my compiler complained. Should I sue the vendor?

> for compounds,
> if (x)
> y;z;a;b;
> else
> c;d;e;f;

... is a syntax error.

--
Eric Sosman
eso...@ieee-dot-org.invalid

Message has been deleted

Richard Bos

unread,
Nov 9, 2009, 11:23:14 AM11/9/09
to
Beej Jorgensen <be...@beej.us> wrote:

> Eric Sosman <eso...@ieee-dot-org.invalid> wrote:
> > I tried your suggestion, with `exit(0)' for `z', and
> >my compiler complained. Should I sue the vendor?
>

> vendor==MICROSOFT && printf("Sue Sue!\n"); // ;-)

You surprise me. I'd expect a M$-written implementation, if it started
emitting girls' names, to choose "Daisy, Daisy...".

Richard

dS...@arcor.de

unread,
Nov 10, 2009, 8:51:06 AM11/10/09
to
On 8 Nov., 02:08, Andrey Vul <andrey....@gmail.com> wrote:
> if (x)
>  y;
> else
>  z;
> becomes
> ((x)&&(y))
> ||(z);

It has to become something like
(x) && (y, 1)
|| (z);

Morris Keesan

unread,
Nov 10, 2009, 11:04:10 PM11/10/09
to

And both forms are illegal if z has void type. See 6.5.13 p2.

--
Morris Keesan -- mke...@post.harvard.edu

dragan

unread,
Nov 22, 2009, 1:13:31 AM11/22/09
to
Andrey Vul wrote:
> C's handling of 'if' leads to a lot of room for obfuscation. All you
> have to do is replace ';' with '|' for compound expressions and add
> parentheses as neccessary.

I see no love in that. "plonk" for false advertising.

Phil Carmody

unread,
Nov 22, 2009, 7:59:24 AM11/22/09
to
Andrey Vul <andre...@gmail.com> writes:
> C's handling of 'if' leads to a lot of room for obfuscation. All you
> have to do is replace ';' with '|' for compound expressions and add
> parentheses as neccessary.

> for compounds,


> if (x)
> y;z;a;b;
> else
> c;d;e;f;
> becomes
> ((x) && ((y)|(z)|(a)|(b))
> ||((c)|(d)|(e)|(f));

Codswallop. You clearly have avoided learning anything about
order of evaluation. Which, given that it's one of the most
commonly discussed things on c.l.c, is either terribly sloppy,
or deliberate. Neither being commendable.

> C is so much fun to obfuscate. Gotta love ISO 9899.
> The result is still more readable than perl, though.

Almost any language can be made practically un readable.
Some just make it trivial, or even natural.

Phil
--
Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1

0 new messages