[SystemSafety] Fwd: Re: Correcting the SECOND screw-up (grovelling apologies)
Derek M Jones
derek at knosof.co.uk
Tue Jul 14 15:17:35 CEST 2020
Roberto,
> sizeof(char) == sizeof(int) == 1
The (common) assumption that this does not occur creates all
manner of interesting behavior, when it does occur.
Other common assumptions tend to involve equalities holding,
such as:
sizeof(int) == sizeof(long) // once a very common assumption
sizeof(long) == sizeof(void *) // still common
I believe the following does not rely on undefined behavior (because
conversion of negative values is defined for unsigned):
#include <limits.h>
#include <stdio.h>
int main(void)
{
char ch=CHAR_MIN;
if (ch < 0)
printf("char is signed\n");
else
printf("char is unsigned\n");
}
--
Derek M. Jones Evidence-based software engineering
tel: +44 (0)1252 520667 blog:shape-of-code.coding-guidelines.com
More information about the systemsafety
mailing list