简体   繁体   English

从'const char *'分配给'char'使得integer从指针没有强制转换

[英]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.

相关问题 从 'char *' 对 'char' 的赋值使指针从没有强制转换的整数 [-Wint-conversion] - assignment to ‘char’ from ‘char *’ makes integer from pointer without a cast [-Wint-conversion] 如何修复 - 从 'char *' 分配给 'char' 使得 integer 从没有强制转换的指针 - How to fix - assignment to ‘char’ from ‘char *’ makes integer from pointer without a cast 从 char * 对 char 的赋值从没有大小写的指针中生成整数 - assignment to char from char * makes integer from pointer without a case 从 'char *' 初始化 'char' 从指针生成整数而不进行强制转换 - initialization of ‘char’ from ‘char *’ makes integer from pointer without a cast 当将char指针分配给字符数组时,赋值使整数指针不带强制转换[默认启用] - assignment makes pointer from integer without a cast [enabled by default] when assigning char pointer to character array 为什么这是“从‘int’到‘char *’的赋值使来自 integer 的指针没有转换 [-Wint-conversion]” - Why this is "assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]" 错误:赋值使指针从整数变成整数,但没有强制转换[-Werror] str1 =(unsigned char *)s1 - error: assignment makes integer from pointer without a cast [-Werror] str1 = (unsigned char*)s1 C 多维字符数组 - 赋值从指针生成整数而不进行强制转换 - C multidimentional char array - assignment makes integer from pointer without a cast 解引用char *时,收到“赋值使指针从整数开始而没有强制转换”警告 - Getting a “assignment makes pointer from integer without a cast” warning when dereferencing char * “警告:赋值使 integer 从没有强制转换的指针”使用字符 malloc - “Warning: assignment makes integer from pointer without a cast” using a char malloc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM