Given this piece of code, does the processor depend on the output or not?

void main() {

        if(-1 > 0U)
                printf("True\n");
        else
                printf("False\n");
}

Is it processor dependent (big endian / little endian)?

+4
source share
2 answers

From C99 6.3.1.8 :

[...] Otherwise, if the operand with an unsigned integer type has a rank greater than or equal to the ranks of the type of another operand, then the operand with an integer type sign is converted to the operand type with an unsigned integer type.

int unsigned int (. 6.3.1.1), -1 unsigned int. 6.3.1.3, (-1 + UINT_MAX + 1) % (UINT_MAX + 1) ( ), , , UINT_MAX , , , 0.

, C (-1 > 0U) true.

+8

Endian-Dependent , x, , , x.

:

int   x = 0x12345678;
char* p = (char*)&x;
char  c = p[0]; // 0x12 on BE and 0x78 on LE

", , ", .

, - BE LE:

struct s {int a; int b;} x = {0x11223344,0x55667788};
int* p = (int*)&x;
int  i = p[0]; // 0x11223344 in both cases

:

- BE LE.

, .

+2

Source: https://habr.com/ru/post/1524487/


All Articles