【发布时间】:2014-05-09 15:57:59
【问题描述】:
我正在使用以下 C 库文件尝试通过 UART 发送 9 个浮点值: https://github.com/microbuilder/LPC1343CodeBase/blob/master/core/uart/uart.c
按照 cmets 中的示例,我想出了以下代码:
#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' 类型,这样我可以发送浮点值吗?
【问题讨论】:
-
不清楚为什么要尝试从
float[]显式转换为float *- 相反,您可能希望从float[]显式转换为uint8_t *到 in效果说“是的,我知道我在做什么”。您确实需要注意元素大小的差异,但您似乎正在处理这个问题。 -
好吧,我并不是 100% 了解自己在做什么,但我想根据给定的答案,事情似乎还不错。谢谢。
-
仅供参考,您只初始化了 testVals 数组的 8 个值。 (在您的序列中错过了 0.4 个。)
-
哈哈谢谢,好收获。
-
小心字节序问题。
标签: c arrays floating-point embedded