Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Misra C:2004 Rule 12.12
#3
phaedsys Wrote:C is not strongly typed. Just because bit wise operators work on integers does not mean you cant get them to work on floats. This is the problem.

This is a bit strong. C might not be very strongly typed, but you certainly can't get away with doing bitwise ops on floats. Both C90 and C99 are quite clear on this, e.g., C99 section 6.3.10 says (of bitwise AND) that "Each of the operands shall have integral type".

A violation of 12.12 _would_ normally have to involve a cast away from the float type to an array of char, int etc. (or a union of a floating-type and an array of chars etc.) and then bitwise ops on the elements of the array. There are plenty of examples of this in, eg, Plauger's "The Standard C Library".

I do not see a situation in which you can break 12.12 without breaking other MISRA-C rules and really this is a design issue rather than a code issue. Really the rule says "if you need to look at floats in detail then use the compiler vendor provided facilities rather than rolling your own, since your own won't be portable". The validity of this statement depends on many things including: the adequacy of the vendor supplied code for your needs; the accessibility of the vendor supplied code (can you verify that it is correct!); the need for portability of the source code (do you care that your own code is target specific?); and not forgetting that not all embedded systems come with complete ANSI libraries -- you may end up having to roll your own.

Having said all that, it is sufficiently rare to have to do this kind of operation on floats that it is probably not worth getting that concerned about it.

stephen
<t></t>


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)