gpt4 book ai didi

C——未声明的首次使用

转载 作者:行者123 更新时间:2023-11-30 20:57:07 25 4
gpt4 key购买 nike

当我执行以下 C 代码片段时,收到以下错误:

“box.c:2:23:错误:‘fblog’未声明(在此函数中首次使用)box.c:2:23:注意:每个未声明的标识符对于它出现的每个函数仅报告一次”

我必须承认我对 C 的经验很少,但我希望有人能发现这个问题。

我尝试将 fblog 定义为 unsigned Short,但这只是引发了另一个错误?!

void putpixel(int x, int y, unsigned short color) {
unsigned short *fblog;
unsigned short *fb = fblog;
*(fb + (y * 240) + x) = color;
}

void drawbox(void) {
int x, y;
for (x = 40; x <= 200; x++) {
putpixel(x, 30, 0xF800);
putpixel(x, 290, 0x001F);
}
for (y = 30; y <= 290; y++) {
putpixel(40, y, 0x7E0);
putpixel(200, y, 0x07E0);
}
}

void main(){
drawbox();
}

最佳答案

fblog 未在 putpixel 函数内声明。尝试全局声明它(这通常是不好的)或将其作为参数传递。

I have tried to define fblog as unsigned short but that just threw another error ?!

这是因为 fb 是指向 unsigned short指针,而不是 unsigned Short 值,所以你有将fblog声明为unsigned Short *,或者使用fblog的地址初始化fb。这取决于你想要得到什么。

关于C——未声明的首次使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14536225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com