Reputation: 73
First - sorry for my bad English :-( Second - I have some intresting task. Preface. Programm will be work on ATMega162. We use macro, becouse functions work very slowly. Even inline... Task. I have a macro:
#define ProvSetBit(reg, bit) (((reg) & (1<<(bit))) != 0)
and check bits turn in very long, unreadable string:
ProvSetBit(SystemStatus[0], COMMAND_ON_DF);
and #define COMMAND_ON_DF 0u
I want to modificate it in:
ProvSetBit(COMMAND_ON_DF);
where COMMAND_ON_DF:
#define COMMAND_ON_DF (SystemStatus[0], 0u)
or something there. But it don't work. Debugger write:"Error[Pe054]: too few arguments in macro invocation". What you can advice me?
Upvotes: 0
Views: 195
Reputation: 171177
If a function is actually inlined, it cannot be slower than a macro doing the same thing - they lead to identical assembly. And a function as trivial as the code you posted is pretty much guaranteed to be inlined. You should ditch the macro and instead investigate why the compiler is not doing inlining for you - perhpas you're not passing the proper compilation flags?
If you reall, really want/have to stick with macros for this one, you can use Boost.Preprocessor to achieve this:
#include "boost/preprocessor/facilities/expand.hpp"
#define ProvSetBit(args) BOOST_PP_EXPAND(ProvSetBit_1 args)
#define ProvSetBit_1(reg, bit) (((reg) & (1<<(bit))) != 0)
#define COMMAND_ON_DF (SystemStatus[0], 0u)
int main()
{
ProvSetBit(COMMAND_ON_DF);
}
Upvotes: 3