The good thing about macros is there is no "option" to the compiler. A compiler can choose to inline or not as it sees fit. There are a bunch of issues involved in making the "to inline or not to inline" decision. With a macro, there are none.lucasart wrote:I solve this problem as follows:Bloodbane wrote:I've got a few macros of that kind there, but I don't like how there is bitshifting going under the hood all the time. The question is does removing that compensate for the increased memory usage. I haven't tested the idea yet so I don't know how it will go, but I don't think it's doomed to fail. I imagine you've tested the idea at some point?
1. move type has strict minimum info, which is fsq tsq and promotion piece (no flag).
2. I do the compression/decompression at once. When a function is given a compressed move and needs to use the components of it, I simply unpack into 3 ints and work with those throughout the function. And vice-versa (function calculates 3 ints and packs at the end to return a move).
Despite the fact that I am writing C code (no C++), I never use macros or even inline. I use extern functions implemented in source files (never in header files to keep those clean). I let gcc's link time optimization do the job of deciding what to inline at the code generation step which is done by at link time (ie. across all compilation units which are bytecode at this stage). Advantage of functions vs macros are obvious (debugging, type safety, avoid subtle syntactic traps when you forget to parenthethize everything in your macros or when you forget the famous "do {...} while (0);" hack...)
I can't believe the C-guy is telling the C++ guy not to use macros. Shouldn't it be the other way around ?
lto is not fully implemented for all formats yet. But if you do as I do, and have a simple "crafty.c" that #include's every source file, you get exactly the same effect because the compiler sees everything at once. And from lots of testing, this actually produces a faster code for me than depending on lto to take care of this.
to each his own, of course, but I have to deal with non-elf, non-macho machines all the time where lto is not always implemented.
