Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add two uint16_t numbers? #41

Open
necto opened this issue Aug 24, 2016 · 5 comments
Open

How to add two uint16_t numbers? #41

necto opened this issue Aug 24, 2016 · 5 comments

Comments

@necto
Copy link
Contributor

necto commented Aug 24, 2016

Hello, I am working with uint16_t numbers. And I am trying simple arithmetic:

#include <stdint.h>

int to_verify()
//@ requires true;
//@ ensures true;
{
  uint16_t x = 1;
  uint16_t y = 38;
  uint16_t z = x + y; //<-- This does not work
}

➡️ Type mismatch. Actual: uint32. Expected: uint16.

How do I compute sum of two short numbers so that VeriFast accepts it?

@necto necto changed the title How to sum two uint16_t numbers? How to add two uint16_t numbers? Aug 24, 2016
@btj
Copy link
Member

btj commented Aug 25, 2016

For now, VeriFast requires that you insert a cast:

uint16_t z = (uint16_t)(x + y);

@necto
Copy link
Contributor Author

necto commented Aug 25, 2016

It does not work. The current VeriFast master branch gives another error:
➡️ No such variable, constructor, regular function, predicate, enum element, global variable, or module: uint16_t
for

#include <stdint.h>

int to_verify()
//@ requires true;
//@ ensures true;
{
  uint16_t x = 1;
  uint16_t y = 38;
  uint16_t z = (uint16_t)(x + y); //<-- for this line
}

@btj
Copy link
Member

btj commented Aug 25, 2016

Ah, yes. The parsing of casts is brittle. This should work:

uint16_t z = (unsigned short)(x + y);

@necto
Copy link
Contributor Author

necto commented Aug 25, 2016

That works. Thank you.

@btj
Copy link
Member

btj commented Sep 2, 2016

Update: Commit 9e8b145 fixes the cast parsing problem. (But a cast is still needed.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants