Hello,
I've run into a strange "bug" today. I'm writing a simple vector library for C. I mostly wanted to do this as a self-examination, but I'm running into a performance issue. My vector library is contained within 2 files. "vector.h" and "vector.c" essentially.
I wanted to mimic behavior I saw in another library, where you can compile the library along with the main if a macro is defined. In my library, if you define BNP_VECTOR_IMPLEMENTATION it does just that. I've been using this with no issues for a while.
So I decided, that some people wouldn't want to use that. So I tried compiling the two files separately. Oddly, I am getting terrible performance. When I revert back, the issues go away. I was wondering if anyone has any guidance?
Here's how I compile seperately:
g++ -O3 main.c vector.c
clang -O3 main.c vector.c
Runtime: ~2000-3000ms
Here's how I compile (when I have BNP_VECTOR_IMPLEMENTATION defined):
g++ -O3 main.c
clang -O3 main.c
Runtime: ~300-400ms
I have my code on GitHub if anyone has the patience to view it:
https://www.github.com/bnpfeife/bnp
Thanks!
EDIT:
Some more puzzling information. When I use "gcc" instead of "g++" it runs at 2000-3000ms. Strange.