如何让 Disp()共用 const 结构与RAM 结构
#include <iostream>
#include <cstring>
typedef struct {
uint8_t reg[2];
}ST_t;
const ST_t AAVal = {44,55}; // 副程式必須加 "const"
ST_t BBVal = {11,22};
//void Disp(const ST_t *Ptr) // 是否可以不用加"const"
void Disp(ST_t *Ptr)
{
printf("AAVal[0] = %d AAVal[1] = %d \n",Ptr->reg[0],Ptr->reg[1]);
}
int main(void)
{
Disp(&AAVal);
// Disp(&BBVal); // error: invalid conversion from ‘const ST_t*’ to ‘ST_t*’ [-fpermissive]
printf("AAVal[0] = %d AAVal[1] = %d \n",AAVal.reg[0],AAVal.reg[1]);
return (0);
}
|