S
Sushil
hi Gurus
I'm a newbie learning C.
I've a question, relevant code snippet is as follows :
typedef unsigned long long ulonglong;
struct foo {
unsigned dummy : 2;
unsigned n : 24;
unsigned c : 3;
unsigned d : 1;
unsigned v : 1;
unsigned g : 1;
};
ulonglong func_foo(void) {
ulonglong addr;
struct foo entry;
/* code that populates entry snipped*/
addr = entry.n << 12;
..
..
}
This caused sign extended value in addr which is not we want.
Would the following be a good fix or clc gurus have a better suggestion?
addr = ((ulonglong)entry.n) << 12;
I'm concerned that there is more to it than what I feel the fix is.
Thanks in advance
- Sushil
I'm a newbie learning C.
I've a question, relevant code snippet is as follows :
typedef unsigned long long ulonglong;
struct foo {
unsigned dummy : 2;
unsigned n : 24;
unsigned c : 3;
unsigned d : 1;
unsigned v : 1;
unsigned g : 1;
};
ulonglong func_foo(void) {
ulonglong addr;
struct foo entry;
/* code that populates entry snipped*/
addr = entry.n << 12;
..
..
}
This caused sign extended value in addr which is not we want.
Would the following be a good fix or clc gurus have a better suggestion?
addr = ((ulonglong)entry.n) << 12;
I'm concerned that there is more to it than what I feel the fix is.
Thanks in advance
- Sushil