+ 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. }

6th Mar 2019, 11:27 PM
aaaa
7 Respuestas
+ 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...!
8th Mar 2019, 5:21 AM
Kuri
Kuri - avatar
+ 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...
7th Mar 2019, 12:40 PM
Kuri
Kuri - avatar
+ 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>.
7th Mar 2019, 1:45 PM
aaaa
+ 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?
7th Mar 2019, 5:43 PM
aaaa
+ 1
Thanks for the answers to both of you. I‘ll just try it and hope for the best.
9th Mar 2019, 5:39 AM
aaaa
0
Thanks for the answer, but I think in c++ int8_t is also signed. The equivalent unsigned should be uint8_t.
7th Mar 2019, 11:50 AM
aaaa
- 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, 🤔🤔🤔
7th Mar 2019, 3:29 AM
Kuri
Kuri - avatar