Are characters automatically expressed in C expressions?

I made an expression to my colleague who was:

"are automatically converted to integers in C expressions, and this is great for performance because processors run faster with their natural word size.

I believe that char promotion behavior is specified somewhere in the standard due to the char rank.

This is the answer I received:

"Characters are not assigned an integer by default. The register size is 32 bits, but several byte values ​​in a string can be packed into a single register as a compiler implementation. This is not always a prediction. The only time you can check for automatic advertising is when the type is passed into the call stack when it is not wrapped around because the C standard officially requires 32-bit values ​​in the memory of the call stack.Many processor architectures are optimized; assembly does not cause 32-bit values, therefore cannot be made about the processor or compiler in this case. "

I’m not sure who is right and what to believe. What are the facts?

+4
source share
4

C

, . C99 6.3.1.8, :

, , . , . , , . , , , , . :

  • -, , , .
  • , , , .
  • , float, , - float.62)
  • . :
    • , .
    • , unsigned , .
    • , , .
    • , , .
    • .

6.3.1.1.2:

: int unsigned int :

  • , int unsigned .
  • _Bool, int, signed int unsigned int

int , int; unsigned int. . .

a char int, char.

( , , , +, - ~, ).

, -.

+8

, char s, .. ( , ) , ( int). . . N3797, §4.5

, :

  • () 32 , .

  • 8 , , 32- ,
    , , .

  • ""?

  • 32- .

  • struct

  • "". ( ).

  • , 32 ,
    , ? ?

...

+4

C - 32- .

CERT:

, , . :

signed char cresult, c1, c2, c3;
c1 = 100;
c2 = 3;
c3 = 4;
cresult = c1 * c2 / c3;

, , , , .

+2

, , . as-if , , , . if (ch==0) ch int, . , (int)ch , ch .

Thus, the actual processor performance and various differences of the CPU are less important than you think for performance; can this optimizer find a decent set of instructions.

0
source

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


All Articles