Standard way of getting a bit pattern of all ones

100 views Asked by At

Is there a strictly conforming way to get a bit-pattern of all ones for an integer in C, without relying on implementation-defined behavior?

On many architectures I can expect -1 and the UINT_MAX family to give such a bit pattern; how portable is this assumption?

1

There are 1 answers

0
Mark Adler On BEST ANSWER

Extremely portable. The C23 standard disallows integer representations that are not 2's complement, so then it will be guaranteed portable.

~0 or ~0U should always work.