Function C: Assign an unsigned function variable with a signed parameter

I recently asked a question. Say we have:

void test(int32_t b){
    printf("value is %d", b);
}

int main(){
    uint32_t a = 43;
    test(a);  
   return 0;
}

What happens when you pass an unsigned variable to a signed parameter? How does a copy of a value work and how does a cast work?

Can someone explain this to me in detail?

thank

+5
source share
3 answers

If the value is small enough, it is simply assigned. Otherwise, it is assigned in accordance with the implementation. Usually this means that he will “turn around”.

6.3.1.3-1

When a value with an integer type is converted to another integer type other than _Bool , if the value can be represented by a new type, it does not change .

, , , , .

; .

+5

a b .

(C99, 6.5.2.2p7) " , , , , , , , ."

, , , , .

(C99, 6.3.1.3p1) " , _Bool, , ."

, :

(C99, 6.3.1.3p3) " : , ".

+3

, , . uint32_t , int32_t, int32_t rollsover .

+2

All Articles