I came Across a line of code in an example that I can not understand how is it being utilized and what benefit on using this type of declaration. following in the part of code extracted from that example
const uint16_t cycles = 8;
typedef uint8_t invariant(value < cycles) TIndex_t;
struct TData
{
uint16_t readings[cycles];
volatile uint16_t sum;
TIndex_t index;
void addReading(uint16_t arg)
writes(*this; volatile)
pre(invar())
pre(arg <= 1023)
post(invar())
{
sum = sum - readings[index] + arg;
readings[index] = arg;
index = static_cast<TIndex_t>((index + 1u) % cycles);
}
void init()
writes(*this; volatile)
post(invar());
ghost(
bool invar() const
returns((forall r in readings :- r <= 1023) && sum == + over readings);
)
This is GNU C++ the struct is a kind of class definition as I can tell