Hi All, I am newbie in this. Is this function declaration right, as it has bit as parameter, void myfunc(unsigned char,bit);
Ashutosh
In C51 it's legal - Or at least, it's accepted.
It's completely standard 'C'.
Here's a quiz:
int Test(void) { int a; return sizeof a; }
Who reached for their favourite 'C' book?
At least 99.999% of existing code would not look like that ;)
Is it - even with 'bit' ?
However, the fact that it's syntactically valid in isolation doesn't mean that it is "right".
To be "right" means that the declaration has to match the definition. As we have no idea what the definition is, the balance of probabilities that one declaration matches one of the infinite space of possible definitions must be vanishingly small. So "No" is the most-likely-correct answer...
;-)
Good catch!
Your original post was a perfectly correct answer to the OP's question. If he'd asked a different question, your answer would have been wrong - nonetheless, the code he posted is standard 'C' (this time with the proviso that it uses implementation specific extensions as permitted by the standard).
Did I get away with that?
Make that 100% round here...
It is very long between each time I see anyone use sizeof as an operator instead of treating it as a function.
Out of "compatibility", I use it as a function just to avoid questions.
... I use it as a function just to avoid questions.
On the other hand, the non-parenthesized version, when used, is an immediate clue that sizeof's operand is not a type. It is a subjective matter whether an individual or shop puts any value on that language feature.