MISRA Discussion Forums
Realizing f strong typing - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: General Questions (https://forum.misra.org.uk/forumdisplay.php?fid=27)
+--- Thread: Realizing f strong typing (/showthread.php?tid=606)



Realizing f strong typing - B3NN7 - 10-01-2009

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:
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:
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 - MMouse - 02-06-2009

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.