例如
const u8 Special_Char_FillVol5[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF, 0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF, 0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF, 0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF, 0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00, 0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF, 0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF, 0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF, }; const CharInfo Special_CharInfo_tbl[10] = {40,Special_Char_FillVol5}; typedef struct { u8 XSize; const u8* pData; } CharInfo; const CharInfo* ptrData;
如上所示,Special_Char_FillVol5是一个const u8类型的数组,总共是16*10个元素;
本人原本是这样取值的
ptrData = &Special_CharInfo_tbl[10];
这里面的ptrData ->ptrData = &Special_Char_FillVol5(本人只是说由上面的代码得到这个等于,但是这样ptrData ->ptrData =赋值就会报错,expression must be a modifiable lvalue:左边表达式必须是个可修改的量)
现在本人要使ptrData ->ptrData从Special_Char_FillVol5的中间开始取值,也就是从Special_Char_FillVol5[80],应该怎么写呢
本人用什么memcpy都会报错expression must be a modifiable lvalue
强制类型转换不知道是不是本人没用好,也会报错。
求高手指点
解决方案
20
*((CharInfo**)&ptrData) = (const CharInfo*)&Special_CharInfo_tbl[10];
20
const CharInfo* ptrData;
这句,ptrData本身不是const限定的,它指向的类型才是限定的,怎么说ptrData只读呢?不是的。
你想取数组第80个元素的值,那很简单嘛:
/* **以下,数组Special_CharInfo_tbl转换为指向其首元素的指针。即,转换为 **const CharInfo *。这正好与=运算符左边ptrData的类型一致,可以赋值。 */ ptrData = Special_CharInfo_tbl; /* **以下通过ptrData取出数组元素的值,并赋给x。 **表达式ptrData [0]的类型是const CharInfo; **表达式ptrData [0].pData的类型是const u8 *; **表达式ptrData [0].pData [80]的类型是const u8; */ u8 x = ptrData [0].pData [80];
格式一下,美观美观。