c - Let gcc inline AND export a function -


given function needs inlined performance reasons (because it's called in loop , don't want call overhead). simplified example:

void increment(int *single_value) {   *single_value++; }  void increment_values(int *array, size_t length) {   for(size_t i=0;i<length;i++) {     increment(&a[i]);   } } 

but want unit test function, example

void test_increment() {   int value = 5;   increment(&value);   assert_equal(value, 6); } 

is possible tell compiler inline function and export it, can link against tests? i'm using gcc, methods working compilers (clang, icc, ...) preferred.

using inline mere hint compiler might @ inline:

"[ . . . ] inline definition not provide external definition function, , not forbid external definition in translation unit. inline definition provides alternative external definition, translator may use implement call function in same translation unit. unspecified whether call function uses inline definition or external definition."

— iso 9899:1999(e), c99 standard, section 6.7.4

in fact, many compilers functions example automatically when being called optimization flags. also, compiler knows better kind of instruction code it's producing, not tell inline.

in situation, i'd let compiler decide, , not use inline @ all. however, if choose use inline, can still use function in unit test, no problem @ all.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -