cancel
Showing results for 
Search instead for 
Did you mean: 

unsigned_int and unsigned_short_int compatibility ?

edgar2
Associate II
Posted on October 30, 2012 at 13:32

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
2 REPLIES 2
Posted on October 30, 2012 at 14:17

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...
edgar2
Associate II
Posted on October 30, 2012 at 21:56

I'm sorry, thanks for the references.