+ 1
__s8 to int8_t
Might there arise a problem, if I put the value of an __s8 variable into an int8_t variable? example: int main { __s8 var1; int8_t var2; // Some code defining var1 from kernel var2 = var1; // Some code with var2. }
7 odpowiedzi
+ 2
Hi.. Suggestion - put some debug code. To confirm any issue in assigning __s8 to int8_t.
After u assign var2=var1, put a condition to display both values, if they are not the same.
Ex:if(var1! = var2) display values of var1 and var1. Hope this helps...!
+ 1
It will be helpful, if you let us know the basic type of _s8 and int_8. These are derived data types using typedef...
+ 1
I found this explenation in another forum. When I‘m back home, i‘ll look for the header:
„The Linux kernel uses u8, u16, u32, (and signed equivalent s8, s16, and s32) internally. The double underscored __u8 & friends are primarily there for when kernel structures get exported to userspace, which should be avoided most of the time. – Joshua Clayton Jan 6 '14 at 21:06“
The int8_t types are fixed width integer types C++11, defined in header <cstdint>.
+ 1
I think the __s# and __u# types are defined in <linux/types.h>. (In my code I included <linux/i2c-dev.h>).
—> https://kernelnewbies.org/InternalKernelDataTypes
For the int#_t and uint#_t types take a look at this.
—> https://en.cppreference.com/w/cpp/types/integer
I‘m getting a __s8 value from the kernel and I wanted to change it to a more standard datatype to make the further calculations. That‘s why I was wondering if it is a good idea to do this with the code shown in the question. Or do I need some kind of conversion?
+ 1
Thanks for the answers to both of you. I‘ll just try it and hope for the best.
0
Thanks for the answer, but I think in c++ int8_t is also signed. The equivalent unsigned should be uint8_t.
- 1
Hi... _s8 - signed integer, it can take values from - 128 to 127.
Int8__t - unsigned integer, and it can take values from the 0 to 255.
U are trying to assign signed value to unsigned... That might be the problem, 🤔🤔🤔