6 ms·
The next time I'm forced to write C code... #define whenceforth for
by greydius 10y ago
The next time I'm forced to write C code...
#define whenceforth for
- Zikes 10y ago#define supposing if #define whereas else
- dopamean 10y agoI know nothing about C. You can alias keywords like that?
- odbol_ 10y ago#define is part of the preprocessor, which does very basic string substitution on the code before compiling. Useful in small doses, but also regularly abused.
- david-given 10y agoAn old classic --- pascal.h: http://thedailywtf.com/articles/_0x23_include__0x22_pascal_0x2e_h_0x22_ http://thedailywtf.com/articles/_0x23_include__0x22_pascal_0...
- goldenkey 10y agoBoost has macro header libs that allow pretty much anything within the macros system limits to be computed. Lookup Boost preproccessor and youll be even more impressed.
- eric_the_read 10y agoMy dad used to tell idiots that he was very impressed with their ideas; one day, he pointed out to me that the impression was not always a positive one. Edit: Not saying Boost is idiotic; just that you may not be positively impressed with their use of preprocessor magic.
- goldenkey 10y agoPretty funny. I have to use that "impressed" fib one day and silently chuckle. Ive actually used Boost preprocessor macros in C for huge benefits to compute variadic functions at compile time. You may not like boost templates or libs but the preproccessor stuff is merely just a turing complete arithmetic language that includes arrays, tuples, lists, and a whole slew of other great things. Its actually quite marvelous how its implemented all from standard macros. A treatise in limited functional programming. I would not want to produce those macros myself..they are insanely clever, just take a look at the source. They use something similar to Church encoding for representing numbers. You can use it without any of the other boost libs or headers. Repetitive code sucks and the BOOST_PP macros are godsend. Im pretty sure you are referring to other 'magic' most likely C++ template stuff. All boost PP does is give you data structures, loop, and arithmetic at compile time. [1] [1] http://www.boost.org/doc/libs/1_61_0/libs/preprocessor/doc/index.html http://www.boost.org/doc/libs/1_61_0/libs/preprocessor/doc/i...
- kagamine 10y agoThe same goes for "quality". It may be a quality product but a poor quality product. If 'quality' is the best word marketing can come up with, maybe marketing isn't of very high quality!
- ball_of_lint 10y agoIn C, #define basically does string substitution, so absolutely. You can also do even more weird things with it, like X macros
- Raticide 10y agoYou can even do evil like #define true false
- MereInterest 10y agoAlong the same lines, for added (and undefined) fun: #define static thread_local #define if(X) if((X) ^ (rand() < 1000)) #define private public #define while if