Re: C and MISRA, blues... (arithmetic shifts)
- From: David Brown <david.brown@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 25 Apr 2008 00:17:17 +0200
Nils wrote:
I'm currently rewriting some numerical code for MISRA compliance.
Signed shifts are not defined by the C-standard, and the code-checker complaints. Well - no big surprise here. I knew that and did it nevertheless. Now I have to rewrite.
But do you do if you need them anyway? I need *lots* of them, so in despair I've just created this monster of unreadable code:
How about:
int ArithmeticShiftRight (int value, unsigned int shift)
{
if (value < 0) {
return -((int) (((unsigned int) (-value)) >> shift);
} else {
return ((int) (((unsigned int) (value)) >> shift);
}
}
It's still horrible, but it probably compiles to better code.
.
- Follow-Ups:
- Re: C and MISRA, blues... (arithmetic shifts)
- From: Thad Smith
- Re: C and MISRA, blues... (arithmetic shifts)
- From: Wilco Dijkstra
- Re: C and MISRA, blues... (arithmetic shifts)
- References:
- C and MISRA, blues... (arithmetic shifts)
- From: Nils
- C and MISRA, blues... (arithmetic shifts)
- Prev by Date: Re: C and MISRA, blues... (arithmetic shifts)
- Next by Date: Re: Large Wireless networks?
- Previous by thread: Re: C and MISRA, blues... (arithmetic shifts)
- Next by thread: Re: C and MISRA, blues... (arithmetic shifts)
- Index(es):
Relevant Pages
|