arrays - Conversion between uint8 and char in C -
i have api implements writing operation eeprom. here declaration:
cyble_api_result_t cyble_storeappdata (uint8 * srcbuff, const uint8 destaddr[], uint32 bufflen, uint8 isforcewrite);
it working when call function , send array parameter srcbuff
has been declared uint8
type.
the problem is, need send char
array pointer it. thinking char
uint8
, compiler warning if send char
array pointer function instead of uint8
. why can't use char
instead of uint8
? here 2 examples of calling function:
static const uint8 datastack_rom[dedicatedromsize] = {0}; uint8 container_id[10]; char prefix[10]; //call function container_id has been declared uint8. working. cyble_storeappdata(container_id,datastack_rom,10,0); //call function prefix has been declared char. not working. cyble_storeappdata(prefix,datastack_rom,10,0);
here warning second call:
passing char[10] parameter of type 'uint8 *' converts between pointers integer types different sign.
aren't char
, uint8
same?
both types 8bits long. difference comes signedness.
- the
uint8
type unsigned. - the
char
type should signed in case. actually, compiler dependent, compilers considerchar
type signed default , have option forcechar
type unsigned if needed. see c99 standard document reference §6.2.5p15:
the implementation shall define char have same range, representation, , behavior either signed char or unsigned char.
char_min, defined in limits.h, have 1 of values 0 or schar_min, , can used distinguish 2 options.
Comments
Post a Comment