News for hackers. Stuff that matters.
Re:Some obscure C features by epilk on Thursday January 25, 2018 @05:57PM (#16235534)
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);
  }
Re:Some obscure C features by apaprocki on Friday January 26, 2018 @12:38AM (#16237246)
A 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 :)
Re:Some obscure C features by pjmlp on Friday January 26, 2018 @10:13AM (#16239717)
The 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.

Re:Some obscure C features by apaprocki on Friday January 26, 2018 @11:03AM (#16240170)
Still 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
Re:Some obscure C features by pjmlp on Friday January 26, 2018 @11:12AM (#16240248)
Thanks for the clarification.

Last time I used it was about 2003.