October 28, 2004
"a := 5" in C? :)
When Nacho showed me yesterday's The Daily WTF, we got to talking about...
No, wait. Go read yesterday's WTF. Really. A Pascal and C programming background would help.
----------
So, now that I assume you've read it, here's the gist. Nacho mentioned that one could also do #define := =
and later on use Pascal-like constructions of the form a := 5
. The only problem was that GCC does The Right Thing(tm) and rejects :=
as a macro name, since a macro name must be, well, a name - that is, a well-formed identifier - you know, letters, numbers, underscores, the works.
Next thing you know, Nacho says that it would be hard to patch GCC to accept a #define := =
construct - and what do you suppose yours truly does? That's right, I was right on it like a swarm of stray tomcats drunk on valerian :)
As a result, here's patch to the GCC preprocessor which parses :=
as a valid identifier. Thus, the following program becomes purrrr-fectly valid:
#include <stdio.h> #define := = int main(void) { int a = 0; a := 5; printf("a is %d\n", a); return (0); }
And here's the result:
[roam@straylight ~/c/misc/foo]> cc -o pasequ pasequ.c [roam@straylight ~/c/misc/foo]> ./pasequ a is 5 [roam@straylight ~/c/misc/foo]>
The patch (not that I would ever expect anyone to use it :) was made against the gcc version 3.4.2 [FreeBSD] 20040728 - the one that is in FreeBSD's 5.x branch for the last couple of months. It may not apply cleanly to other 3.2, 3.3 or 3.4 versions, and it will not apply at all to 2.x, since cpplex.c does not even exist there. Still, it Works For Me(tm), and that's enough for the whole why-the-hell-not fun part :)
(and yes, when I told Vasil Kolev about it, his comment "that's sick!" *might* have been spot-on :)
Posted by roam at October 28, 2004 01:39 PM
well, that's a start.. :-)
lecture ][ - How To Write Unmaintainable Code
...
Preach it, brother!
And of course, you've seen http://www.freevbcode.com/ShowCode.Asp?ID=2547 - "How to Write Unmaintainable Code", right? :)
Posted by: Peter Pentchev at October 29, 2004 04:47 PMAs a blogger, what are your thoughts on Podcasting?Mark
Posted by: Mark - The Podcasting Guy at December 1, 2004 08:05 PM