[英]assignment to 'char' from 'const char *' makes integer from pointer without a cast
I am very new to C and am encountering an issue while trying to store my next_frame
in a variable.我是 C 的新手,在尝试将next_frame
存储在变量中时遇到问题。 Any help would be great as I think this is probably something simple I'm just missing.任何帮助都会很棒,因为我认为这可能是我所缺少的简单东西。
If I just change the following it works fine, only when I try to store the next_frame
in a variable does it not compile.如果我只是更改以下它工作正常,只有当我尝试将next_frame
存储在变量中时它才不会编译。
// Doesn't compile
oled_write_raw_P(next_frame, FRAME_SIZE);
// Compiles
oled_write_raw_P(frames[abs((FRAME_COUNT - 1) - current_frame)];, FRAME_SIZE);
Full Code完整代码
#define FRAME_COUNT 5 // Animation Frames
#define FRAME_SIZE 256
#define FRAME_DURATION 200 // MS duration of each frame
// Variables
uint32_t timer = 0;
uint8_t current_frame = 0;
char next_frame;
static void render_animation(void) {
static const char PROGMEM frames[FRAME_COUNT][FRAME_SIZE] = {
// Images here, removed for example
};
// If timer is more than 200ms, animate
if (timer_elapsed32(timer) > FRAME_DURATION) {
timer = timer_read32();
current_frame = (current_frame + 1) % FRAME_COUNT;
next_frame = frames[abs((FRAME_COUNT - 1) - current_frame)];
// Set cursor position
oled_set_cursor(128, 0);
// Write next frame
oled_write_raw_P(next_frame, FRAME_SIZE);
}
}
These are the errors:这些是错误:
error: assignment to 'char' from 'const char *' makes integer from pointer without a cast [-Werror=int-conversion] next_frame = frames[abs((FRAME_COUNT - 1) - current_frame)];错误:从'const char *'分配给'char'使得integer从指针没有转换[-Werror = int-conversion] next_frame = frames [abs((FRAME_COUNT - 1) - current_frame)];
error: passing argument 1 of 'oled_write_raw_P' makes pointer from integer without a cast [-Werror=int-conversion] oled_write_raw_P(next_frame, FRAME_SIZE);错误:传递 'oled_write_raw_P' 的参数 1 使指针来自 integer 而无需强制转换 [-Werror=int-conversion] oled_write_raw_P(next_frame, FRAME_SIZE);
The line线
next_frame = frames[abs((FRAME_COUNT - 1) - current_frame)]
does not make sense.没有意义。
The variable next_frame
, to which you are assigning a value, has the type char
.您要为其赋值的变量next_frame
的类型为char
。 However, you are assigning it the expression但是,您正在为其分配表达式
frames[abs((FRAME_COUNT - 1) - current_frame)]
which decays to a pointer to the first element of the sub-array, so the expression evaluates to a value of type const char *
.它衰减为指向子数组第一个元素的指针,因此表达式的计算结果为const char *
类型的值。
I'm not exactly sure what you want to accomplish, but I guess the solution to your problem is to change the type of next_frame
to const char *
, so that the types match.我不确定你想要完成什么,但我想你的问题的解决方案是将next_frame
的类型更改为const char *
,以便类型匹配。 In order to do this, you can change the line为此,您可以更改行
char next_frame;
to:到:
const char *next_frame;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.