Page 1 of 1

Realizing f strong typing

Posted: Sat Jan 10, 2009 2:48 pm
by B3NN7
Hello,

I have a problem by realizing a strong typed library function. The library function shall get a pointer to one byte and the number of bytes up on the pointer to be read.

But I does have the requirement that only local variables on the stack or global variables at the data area of the C Application may be processed by my function.

Here is a bad example:

Code: Select all

void function(const void* const Data_pv, const uint8_t Size_u8)
{
   ...
}

void* Address = 0xFFAF;

function(Address, 8);
It shall not be possible to pass a pointer on void.

Here is a good example

Code: Select all


uint32_t Data_u32 = 5;

function( (uint8_t*)&Data_32, sizeof(Data_u32));

Is there a rule of MISRA C supporting me by realizing my described problem ?

Thanks B3NNY

Re: Realizing f strong typing

Posted: Tue Jun 02, 2009 11:29 am
by MMouse
There isn't realy a single MISRA rule for this. This is inthe catagory of all comments will be meaningful. You need to catch this with human reviewing

See rule 21.1 which says something about run time checking.
You need a static checker with strong typing and dynamic or unit testing.