Does anybody have any insight into the efficiency gains or losses of using the Keil C51 bit type as a return value in a function?
Relavent manual page is here: http://www.keil.com/support/man/docs/c51/c51_le_funcretvals.htm
I hadn't really realized it was a possibility until today, and I see that it's implemented by using the Carry flag, which is neat. I've been trying to think of instances where it might result in undesirable behavior, or would be less efficient for some reason, but I think it seems pretty safe and marginally faster for functions that need only return a boolean.
Does anybody have any opinions for or against making use of it freely in 8051 C?
Barring, clearly, where it's prohibited by the compiler: http://www.keil.com/support/man/docs/c51/c51_le_bit.htm
I hadn't seen a previous post where this was discussed regarding recommended practices, so I thought I'd put out feelers into the collective.
Dan
You can see what difference it makes by looking at the generated code.
Using it clearly impacts portability...
Definitely impacts portability, I think that's worth getting down in print, I'm pretty sure no ANSI C systems support bit function returns. But there's so much odd C code for 8051 systems, often idiosyncratic seeming because the programs are custom optimized by just these kinds of intuited understandings of what the tradeoffs are in the hardware and in the compiler for certain choices of phrase.
I haven't yet done my own compilation tests (though I plan to later regardless of what anyone posts), but in the meantime I just wondered if anybody else had any strong already-formed (and possibly hard-won) opinions on this topic that would be worth sharing on the forum...
Portability of the BIT shouldn't be a great issue. Especially with sensible defines.
There is a lot of other C51 specifics that can affect portability far more.
If your task requires extreme optimisations then it's worth considering their use. But it is just as useful to consider a more capable core; such as ARM.
Actually, it is things like the bit access features which can make the 8051 a "more capable core" in cases where it can be used to advantage.
Of course, taking advantage of specific core feature is inherently not portable - so you have to decide which is most important to you for the particular application at hand...
But for much boolean use, it's possible to write portable code that uses bit variables when compiled on 8051.
But the reverse isn't true, i.e. a portable C/C++ program will have problems moving to bit variables, in case it uses arrays pointers to work with the boolean values.
It's always good to consider what possible abstractions that may be used without too big costs.
That's why I used the word consider!