“C variable type sizes are machine dependent.” Is it really true? signed & unsigned numbers ;

前端 未结 6 829
旧时难觅i
旧时难觅i 2020-12-11 07:18

I\'ve been told that C types are machine dependent. Today I wanted to verify it.

void legacyTypes()
{
    /* character types */
    char k_char = \'a\';

           


        
6条回答
  •  温柔的废话
    2020-12-11 07:46

    Real compilers don't usually take advantage of all the variation allowed by the standard. The requirements in the standard just give a minimum range for the type -- 8 bits for char, 16 bits for short and int, 32 bits for long, and (in C99) 64 bits for long long (and every type in that list must have at least as large a range as the preceding type).

    For a real compiler, however, backward compatibility is almost always a major goal. That means they have a strong motivation to change as little as they can get away with. As a result, in practice, there's a great deal more commonality between compilers than the standard requires.

提交回复
热议问题