我已經定義下面的函數,其是公由郵資-C證明:斷言上指針陣列
//ensures array <= \result < array+length && *\result == element;
/*@
requires 0 < length;
requires \valid_read(array + (0 .. length-1));
assigns \nothing;
behavior in:
assumes \exists int off ; 0 <= off < length && array[off] == element;
ensures *\result == element;
behavior notin:
assumes \forall int off ; 0 <= off < length ==> array[off] != element;
ensures \result == 0;
disjoint behaviors;
complete behaviors;
*/
int* search(int* array, int length, int element){
int *tmp;
/*@
loop invariant 0 <= i <= length;
loop invariant \forall int j; 0 <= j < i ==> array[j] != element;
loop assigns i;
loop variant length-i;
*/
for(int i = 0; i < length; i++)
{
if(array[i] == element)
{
tmp = &array[i];
//@ assert *tmp==element;
}
else
{
tmp = 0;
}
}
return tmp;
}
我用它在以下主要條目:
int main(){
int arr[5]={1,2,3,4,5};
int *p_arr;
p_arr = search(arr,5,4);
//@ assert *p_arr==30;
return 0
}
我想知道爲什麼frama-c給出斷言「// @ assert * p_arr == 30;」真的,我不明白。
感謝
哪個版本的frama-c?哪些選項?誰說斷言是有效的:WP? – Anne
謝謝您的回覆,版本爲磷,選項爲:frama-c-gui -wp -rte -val,GUI上的子彈爲橙色。這對你來說有足夠的信息嗎? –
我會說斷言線上的子彈是綠色的,對不起 –