Re:Having fun abusing the C language
by raverbashing on Tuesday October 25, 2016 @11:34AM
(#12788809)
Ah there are funnier, less obvious ways
[ Parent
| on HN ]
I mean, as the sibling notes, there's redefining true as false, but I think making all structs unions is much funnier, especially in that it's a uniquely C proposition. There are other languages that allow redefinition of true and false.
Also, I'm not sure how you think it's particularly obvious (as opposed to any other #define trick). It does only work if the project isn't warning-safe, as there are various ways this'll trigger ugly warnings (eg. using designated initializer syntax causes re-initialization warnings), but even then the warnings don't tend to actually tell you it's a union all of a sudden.
If you have others, I'd like to hear them.
Re:Having fun abusing the C language
by raverbashing on Wednesday October 26, 2016 @05:07AM
(#12794979)
- Change the alignment of structs
- Remember the order of includes change how they are applied. Have a #define that changes something in a .h that's included in some files but not in others
- (Depending on the software) redefine rand() to be almost predictable or with a short loop
Re:Having fun abusing the C language
by qwertyuiop924 on Tuesday October 25, 2016 @03:36PM
(#12790975)
#define if while
#define else while(!true){}
That should be interesting.
Re:Having fun abusing the C language
by qwertyuiop924 on Tuesday October 25, 2016 @11:45AM
(#12788891)
The classic is:
#define TRUE FALSE
or the even more pernicious: #define 1 0I once chased a bug which turned out to be: someone had #defined the letter 'T' as something else, in a chain of #include files nested 19 deep. Completely screwed up a bunch of C++ templates.
Straight from the Ministry of Truth that one...
Re:Having fun abusing the C language
by therealidiot on Tuesday October 25, 2016 @02:57PM
(#12790619)
I read somewhere about someone redefining goto as goat, but I can't remember where.
Might have been the Lua Programming Gems book...