2012-10-30 05:32 AM
Hi there,
May be this is a silly question, but could someone explain me to how we use unsigned int and unsigned short int types together ? Here is an exemple from a simple working code (gpio.c* of STM32 VL Discovery MCU). In this code, I put in comments the questions running through my head.
volatile
unsigned
int
a;
unsigned
short
int
b;
unsigned
int
c;
unsigned
char
function_0()
if
( (a&b) != c)
// how is it possible to use a logic operation on two different types and then compare the result with an other type ?
...
else
....
}
unsigned
short
int
function_1(...)
{
....
return
( (unsigned
short
int
) a) ;
// As we convert one to the other, I understand from this line that the two types aren't compatible . right ?
}
void
function_2(...)
{
....
a = a | b;
// same question as for function_0().
a &= (~b);
}
(*) : I replaced the original variables : GPIO_x->IDR, GPIO_Pin and (unsigned int) )BIT_RESET with respectively: a, b, and c to make the code easier to read.
I wish this was clear and I'd much appreciate your help.
Thanks.
#'c'-textbook-question #unsigned #short #int
2012-10-30 06:17 AM
This is a 'C' textbook question - nothing specifically to do with STM32.
Suggested references:http://blog.antronics.co.uk/2010/12/12/things-you-shouldve-learned-in-c-class-0-introduction/
Integer Promotion is the topic you're looking for...2012-10-30 01:56 PM
I'm sorry, thanks for the references.