4 ms·
I also encountered the last problem, it can be handled pretty easily with __attribute__((constructor)): void (*_test_functions[NTEST_FUNCTIONS])(void); int
by epilk 9y ago
I also encountered the last problem, it can be handled pretty easily with __attribute__((constructor)):
void (*_test_functions[NTEST_FUNCTIONS])(void);
int _test_function_idx;
#define TEST_FUNCTION(fname) \
void fname(void); \
__attribute__((constructor)) static void _init_ ## fname (void) { \
_test_functions[_test_functions_idx++] = fname; \
} \
void fname()
TEST_FUNCTION(test_foo_bar) {
assert(foo_bar == 0);
}
- apaprocki 9y agoA quite fun, related feature of the AIX linker, is that it will automatically make any function name prefixed with "__sinit_" statically invoked the same as this attribute does. So you name the function a certain way to take care of AIX/xlc, add pragmas to take care of other UNIX vendor compilers add the attribute for any GCC-based (or compatible) compiler, and they are actually pretty cross-platform! Not... that... I would use these all the time or anything like that :)
- pjmlp 9y agoThe fun was even better in the old days, where each UNIX had a different concept of what a shared object should be. AIX used to implement shared objects just like on Windows, using an export definitions file and import libraries, for example.
- apaprocki 9y agoStill does to this day. And it has a machine-wide cache of libraries, so simply updating the library and restarting the processes isn't enough to get the new version -- you have to be aware it could be in the cache and might need to be manually flushed by someone with elevated access. shudder
- pjmlp 9y agoThanks for the clarification. Last time I used it was about 2003.