C编程UART函数不兼容指针类型

标签 c arrays floating-point embedded

我正在使用以下 C 库文件尝试通过 UART 发送 9 个浮点值: https://github.com/microbuilder/LPC1343CodeBase/blob/master/core/uart/uart.c

按照评论中的示例,我想出了以下代码:

#define UARTBUFFERSIZE 36 
float testVals[9] = {0.1, 0.2, 0.3, 0.5, 0.6, 0.7, 0.8, 0.9}; //global, just for testing

在我的主要代码中,我有以下行来尝试发送 testVals:

uartSend((float *)testVals, UARTBUFFERSIZE); 

main.c:94:4: warning: passing argument 1 of 'uartSend' from incompatible pointer type
core/uart/uart.h:67:6: note: expected 'uint8_t *' but argument is of type 'float *'

我是否必须使用“uint8_t”类型,这样我才能发送浮点值吗?

最佳答案

只需将其转换为uint8_t*,它是安全的。您的 float 设置正确 9 个 float -> 9 x 4 字节。

关于C编程UART函数不兼容指针类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23569048/

相关文章:

c - malloc、free 和变量的重新定义

arrays - 如何在 perl 中正确创建和循环 3D 数组?

javascript - 将对象属性中的数组合并到对象数组中

c++ - PIC 编程 - 将多个按钮的值获取到一个端口

我可以通过 C 套接字发送 json 数据吗?

python - 如何使用 sly 只获取功能 block

c++ - 有符号零的最小值和最大值

javascript - 在给定对象键匹配条件的情况下,将键添加到数组集合内的对象集

string - 在 MATLAB 中将数字转换为字符串

c - 打印链表的float元素显示不正确?