c++ - Calling random altered functions based on an original function -


let's have 10 altered functions each original function, same, different process of execution , maths. want call random function out of 10 altered functions instead of original function every time original function supposed used in code. how can , avoid getting 9 other altered functions compiled, not selected random , won't used?

this hand out "different" build each receiver unique signature. possible way of doing it, can think of, have folder each original function holds 10 separate include files, each altered function. kinda messy, it's way can think of.

if there's easier way of doing, want achieve, please let me know. example adding junk code original function randomly on compiling - better, since it's dynamic. can't imagine of way on how it.

here's pseudo: http://pastebin.com/v7hv53ns

this problem can divided 2 smaller problems.

part 1: determine variant give receiver. equivalent mapping signatures {1,...,10} without collision. incidentally, means there can ten unique signatures @ most. (if more 1 function, must decide whether each receiver shall receive a set of unique implementations or unique set of implementations, never mind now.) not seem part you're asking about, let's suppose put logic executable (e.g. script) called pickvariant.

part 2: given choice of variant, compile variant , construct package (executable, library, whatever) receiver. way:

in makefile:

variant := $(shell pickvariant $(signature))  foo.o: foo.cc     @$(cxx) $< -dvariant=$(variant) -c -wall -o $@ 

in foo.cc:

int addtwo(int n) {   int res; #if variant==1   res = n+2; #elif variant==2   res = n+1+1; #elif variant==3   res = 5+n-3; ... #elif variant==10   res = 2*n+2-n; #endif    return res; } 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -