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

result of 16bit unsigned arithmetics treated as signed (IDFGH-13747) #14609

Closed
3 tasks done
caspehre opened this issue Sep 20, 2024 · 4 comments
Closed
3 tasks done

result of 16bit unsigned arithmetics treated as signed (IDFGH-13747) #14609

caspehre opened this issue Sep 20, 2024 · 4 comments
Labels
Status: Opened Issue is new

Comments

@caspehre
Copy link

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

It seems result of unsigned short arithmetics is treated as signed. Consider following code, the u32 example works, but not the u16 example.

volatile unsigned long u32integer1 = 10;
volatile unsigned long u32integer2 = 0xFFFFFFFF;

volatile unsigned short u16integer1 = 10;
volatile unsigned short u16integer2 = 0xFFFF;

void AppTask(void){
if ((u32integer1 - u32integer2) > 10){
printf("u32 works\n");
}else{
printf("u32 does not work\n");
}
if ((u16integer1 - u16integer2) > 10){
printf("u16 works\n");
}else{
printf("u16 does not work\n");
}
}

@espressif-bot espressif-bot added the Status: Opened Issue is new label Sep 20, 2024
@github-actions github-actions bot changed the title result of 16bit unsigned arithmetics treated as signed result of 16bit unsigned arithmetics treated as signed (IDFGH-13747) Sep 20, 2024
@igrr
Copy link
Member

igrr commented Sep 20, 2024

That's the correct observation, but it's not specific to ESP-IDF.

@caspehre
Copy link
Author

Ok, then I learned something new, I thought it was reasonable to assume second example should work. I guess this issue is closed then?

@caspehre
Copy link
Author

Since this seems to be something not specific to xtensa, I close this issue

@igrr
Copy link
Member

igrr commented Sep 20, 2024

Yeah, that's just one the many of C language's footguns, unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new
Projects
None yet
Development

No branches or pull requests

3 participants