We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
2 questions:
1) See http://www.keil.com/support/man/docs/c51/c51_le_bit.htm I don't understand the meaning of the following description. "Functions that disable interrupts (#pragma disable) and functions that are declared using an explicit register bank (using n) cannot return a bit value. The Cx51 Compiler generates an error message for functions of this type that attempt to return a bit type."
Can someone provide more explanagtion and example for my reference ? Thanks!
2) For interrupt, see http://www.keil.com/support/man/docs/c51/c51_le_interruptfuncs.htm "Interrupt function declarations may not include a return value. They must be declared as void (see the above examples). The compiler emits an error message if any attempt is made to define a return value for the interrupt function. The implicit int return value, however, is ignored by the compiler."
Why interrupt function(interrupt service routine, ISR) can not have return value? Should declare as void ?
Can someone tell me why ? Thanks!
ONE:
A return value of a bit cannot be used when the function requires a specific register bank because (within the processor) the register that controls the register bank selection also contains the place where a returned bit would be given.
The sequence takes the form:
Function_that_states_specific_bank_and_returns_bit PreserveRegisterThatSpecifiesRegisterBank SelectRegisterBank DoTheJob ConditionReturnValue_InCarry RestoreOriginalValueOfRegisterThatSpecifiesRegisterBank <<< This register contains the carry flag! Return
So, just consider it and you will see why the compiler doesn't like it.
Of course, the exit sequence of the compiler could be modified to accommodate the situation, but it would be rather inefficient. Keil obviously decided that it would be too costly a facility to support.
TWO:
If you want to write a function that returns a value, then that value would have to be taken by the called.
In the case of an interrupt, consider what calls the function and what would the return value be expected to be taken by.
If the value cannot be used (which it can't) then there is no reason to return any value. Hence the return type for that interrupt routine might as well be void.
The compiler simply enforces the obvious requirement.