我有一个API来实现对EEPROM的写入操作。下面是它的声明:在C中的uint8和char之间的转换
CYBLE_API_RESULT_T CyBle_StoreAppData (uint8 * srcBuff, const uint8 destAddr[], uint32 buffLen, uint8 isForceWrite);
它运作良好时,我调用此函数,并发送一个阵列参数已被宣布为uint8型srcBuff。
问题是,我需要发送char数组指针。我在想char已经是uint8,但是如果我发送一个char数组指针而不是uint8,我会得到一个编译器警告。为什么我不能使用char而不是uint8?下面是调用该函数的2个例子:
static const uint8 datastack_ROM[dedicatedRomSize] = {0};
uint8 Container_ID[10];
char Prefix[10];
//Call the function with Container_ID which has been declared as uint8. This is working.
CyBle_StoreAppData(Container_ID,datastack_ROM,10,0);
//Call the function with Prefix which has been declared as char. This is NOT working.
CyBle_StoreAppData(Prefix,datastack_ROM,10,0);
下面是第二个电话警告:
passing char[10] to parameter of type 'uint8 *' converts between pointers to integer types with different sign.
是不是char和uint8一样吗?
+1
错误消息中的重要内容是关于“不同符号”的部分。这意味着你的'char'类型是'signed',而'uint8'是(假设在这里)'unsigned'。这可能不会是一个大问题,所以你应该只能够投射你的指针:'CyBle_StoreAppData((uint8 *)Prefix,...)' –
+0
这似乎违反了约束条件,请注意:http:// stackoverflow。com/questions/30535814/pass-unsigned-char-pointer-to-atoi-without-cast –
+0
@GiorgiMoniava我看过类似的问题,但我想我找不到那个。我怎么能提到有类似的问题呢?还是我需要那样做? –