如何跟踪 C 中结构成员值的变化?
struct STATE{
uint8 bit;
uint8 cop;
}
STATE *state_array[1024];
state_aray[0]->bit = 8;
state_aray[0].cop = 8;
state_aray[1]->bit = 0;
state_aray[1].cop = state_aray[1]->bit & 8 != state_aray[0]->bit & 8
state_aray[2]->bit = 12;
state_aray[2].cop = state_aray[1]->bit & 8 != state_aray[0]->bit & 8 && state_aray[2]->bit & 8 != state_aray[1]->bit & 8
state_aray[3]->bit = 0;
state_aray[3].cop = state_aray[1]->bit & 8 != state_aray[0]->bit & 8 && state_aray[2]->bit & 8 != state_aray[1]->bit & 8 && state_aray[3]->bit & 8 != state_aray[2]->bit & 8
state_aray[4]->bit = 8;
state_aray[4].cop = ...
state_aray[5].cop = ... ...
...
state_aray[100].cop = ... ...... ......... ....... ......... ....... ...... ....... ............... ........ ...... ............ .... ......... ...... ..
有没有办法只使用 state_aray[i-1]->cop 和 state_aray[i-1]->bit 和 state_aray[i]->bit 来获取 state_aray[i]->cop?
tks
struct STATE{
uint8 bit;
uint8 cop;
}
STATE *state_array[1024];
state_aray[0]->bit = 8;
state_aray[0].cop = 8;
state_aray[1]->bit = 0;
state_aray[1].cop = state_aray[1]->bit & 8 != state_aray[0]->bit & 8
state_aray[2]->bit = 12;
state_aray[2].cop = state_aray[1]->bit & 8 != state_aray[0]->bit & 8 && state_aray[2]->bit & 8 != state_aray[1]->bit & 8
state_aray[3]->bit = 0;
state_aray[3].cop = state_aray[1]->bit & 8 != state_aray[0]->bit & 8 && state_aray[2]->bit & 8 != state_aray[1]->bit & 8 && state_aray[3]->bit & 8 != state_aray[2]->bit & 8
state_aray[4]->bit = 8;
state_aray[4].cop = ...
state_aray[5].cop = ... ...
...
state_aray[100].cop = ... ...... ......... ....... ......... ....... ...... ....... ............... ........ ...... ............ .... ......... ...... ..
is there a way to only use state_aray[i-1]->cop and state_aray[i-1]->bit and state_aray[i]->bit to get state_aray[i]->cop?
tks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
行不通。与 OOP 的“this”或“self”概念相反,C 中不存在“我是该结构的成员”机制。
这就是为什么在 C 中,您只需隐藏结构实现并提供函数来更改您偷偷设置其他值的值。
Won't work. There's no "I'm a member of this structure" mechanism in C, as opposed to OOP's "this" or "self" concepts.
That's why in C you simply hide your structure implementation and provide functions to change the values in which you sneakily set other values.