4 ms·
This is really nice. I wonder if there is a way to make this work without constructors.
by matheusmoreira 5y ago
This is really nice. I wonder if there is a way to make this work without constructors.
- deleted 5y ago[deleted]
- cozzyd 5y agoCan possibly be done with a custom section, though not sure that is better and might require fancy compiler flags.
- cozzyd 5y agoIndeed, I just made a POC with compiler sections: https://github.com/cozzyd/examc https://github.com/cozzyd/examc This implementation only works with gcc though probably (it uses the automatic __start_SECTION and __stop_SECTION that gcc generates but clang doesn't seem to... there are likely hacks to make this work anyway though). In principle, this approach allows interspersing your tests throughout a shared library instead of all in one file (though in that case you wouldn't want the testing function to be called main and you would need a separate driver program for test).