Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Dirty use of the C preprosscor

Name: Anonymous 2012-02-06 1:58


#define func_name do_some_shit
#define func_to_do do_shit

#define func_body \
int func_name(int x, int y) \
{ \
    /*
     * long function body
     */
    func_to_do(i, stack); \
     /* etc */
}

func_body

#define func_to_do SDL_TakeAShit
#define func_name do_some_other_shit

func_body


I just used this trick and I feel really bad about it. I abused the preprocesscor but it worked and saved me from writing a long function twice with minor changes.

Am I a bad person?

Name: Anonymous 2012-02-06 5:11

Have some soap.

Why stop here? Put the function in a file generic_func.inc without putting it in a macro or anything. It looks almost like any other .c file. Then when you need to create a function do:


#define func_to_do SDL_TakeAShit
#define func_name do_some_other_shit
#include "generic_func.inc"
#undef func_to_do
#undef func_name

Name: Anonymous 2013-11-30 8:02

░░░░░░░▄▀▀▀▀▀▀▀▀▀▀▄▄░░░░░░░░░
░░░░▄▀▀░░░░░░░░░░░░░▀▄░░░░░░░
░░▄▀░░░░░░░░░░░░░░░░░░▀▄░░░░░ YOU HAVE BEEN VISITED BY
░░█░░░░░░░░░░░░░░░░░░░░░▀▄░░░ LE 'FEEL OF NO GF
░▐▌░░░░░░░░▄▄▄▄▄▄▄░░░░░░░▐▌░░
░█░░░░░░░░░░░▄▄▄▄░░▀▀▀▀▀░░█░░ A qt 3.14 gf will come to you,
▐▌░░░░░░░▀▀▀▀░░░░░▀▀▀▀▀░░░▐▌░ but ONLY if you post a
█░░░░░░░░░▄▄▀▀▀▀▀░░░░▀▀▀▀▄░█░ `>tfw no GF on this thread
█░░░░░░░░░░░░░░░░▀░░░▐░░░░░▐▌
▐▌░░░░░░░░░▐██▀█▄░░░░░░█▀█░▐▌
░█░░░░░░░░░░░▀▀▀░░░░░░▀▀▀▀░▀▄
░▐▌░░░░▄░░░░░░░░░░░░░▌░░░░░░█
░░▐▌░░▐░░░░░░░░░░░░░░▀▄░░░░░█
░░░█░░░▌░░░░░░░░▐▀░░░░▄▀░░░▐▌
░░░▐▌░░▀▄░░░░░░░░▀░▀░▀▀░░░▄▀░
░░░▐▌░░▐▀▄░░░░░░░░░░░░░░░░█░░
░░░▐▌░░░▌░▀▄░░░░▀▀▀▀▀▀░░░█░░░
░░░█░░░▀░░░░▀▄░░░░░░░░░░▄▀░░░
░░▐▌░░░░░░░░░░▀▄░░░░░░▄▀░░░░░
░▄▀░░░▄▀░░░░░░░░▀▀▀▀█▀░░░░░░░

Don't change these.
Name: Email:
Entire Thread Thread List