my question may confuse you, know both different types (signed char , char), company coding guidelines specifies use int8_t instead of char.
so, want know, why have use int8_t instead of char type. there best practices use int8_t?
the use of int8_t circumstances - when type used calculations signed 8-bit value required. calculations involving strictly sized data [e.g. defined external requirements 8 bit in result] (i used pixel colour levels in comment above, uint8_t, negative pixel colours don't exist - except perhaps in yuv type colourspace).
the type int8_t should not used replacement of char in strings. can lead compiler errors (or warnings, don't want have deal warnings compiler either). example:
int8_t *x = "hello, world!\n"; printf(x); may compile fine on compiler a, give errors or warnings mixing signed , unsigned char values on compiler b. or if int8_t isn't using char type. that's expecting
int *ptr = "foo"; to compile in modern compiler...
in other words, int8_t should used instead of char if using 8-bit data caclulation. incorrect wholesale replace char int8_t, far guaranteed same.
if there need use char string/text/etc, , reason char vague (it can signed or unsigned, etc), usign typedef char mychar; or should used. (it's possible find better name mychar!)
edit: should point out whether agree or not, think rather foolish walk whoever in charge of "principle" @ company, point @ post on , "i think you're wrong". try understand motivation is. there may more meets eye.
Comments
Post a Comment