I recently conducted a small experiment where I tried to override a single function from a third party library that we use. The reason for doing this is that I wanted to use a customized version of the function in my testbench and I didn't want to add preprocessor directives to the application code to use different versions if compiling for testbench or not.
Unfortunally I must say I failed. At first I just tried to add a function with the same name and input params to the same namespace. Didn't have any high hopes that it would work, and of course it didn't. The linker had no idea what to do when it found two identical functions so it just exited with an error.
Next I thought about writing a stubbed version of the entire lib. Not a bright idea either. The lib is very extensive and stubbing every function would take forever and would leave me with a testbench that really doesn't test the functionality at all.
Finally I turned to my old friend Google. First I thought that I had struck gold when I got a hit on Stack Overflow: http://stackoverflow.com/questions/617554/override-a-function-call-in-c
Reading through the answers though they all seemed to include modifications of the application code.
Well I guess that if Stack Overflow can't help me no one can. Hello #ifdef!
Unfortunally I must say I failed. At first I just tried to add a function with the same name and input params to the same namespace. Didn't have any high hopes that it would work, and of course it didn't. The linker had no idea what to do when it found two identical functions so it just exited with an error.
Next I thought about writing a stubbed version of the entire lib. Not a bright idea either. The lib is very extensive and stubbing every function would take forever and would leave me with a testbench that really doesn't test the functionality at all.
Finally I turned to my old friend Google. First I thought that I had struck gold when I got a hit on Stack Overflow: http://stackoverflow.com/questions/617554/override-a-function-call-in-c
Reading through the answers though they all seemed to include modifications of the application code.
Well I guess that if Stack Overflow can't help me no one can. Hello #ifdef!
Kommentarer
Skicka en kommentar