Solution 1 is clearly the good one, as it abstracts over the memory layout chosen by your compiler, and by Cil within Frama-C.
Solution 2 is in fact incorrect as written. Your range p+(0..15)
must be understood using pointer arithmetics on objects of type struct someStruct
, and you are in fact requesting that p
points to an area where 16 * sizeof(struct someStruct)
bytes are valid.
A correct reformulation of solution 2, for standard memory layouts, would have been
\valid(((char*)p)+(0..15))
In fact, the ACSL reference manual explicitly mentions the following equivalence page 56. (I have removed labels for clarity.)
\valid(p) <==> \valid(((char*)p)+(0..sizeof(*p))
For strings, the cast (char*)p
becomes superfluous, as strings are already pointers to char. Thus, writing valid(p+(0..strlen(p))
requires that p
points to a memory are where strlen(p)+1
bytes are valid -- but only because p
has type char*
, and sizeof(char)=1
.