[英]Compiler Error when using a struct
我在初始化结构时遇到了一个奇怪的编译器错误。
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
struct RadarData
{
unsigned int messageID : 32;
unsigned int time : 32;
float az;
float el;
};
struct RadarData sendData;
sendData.az = 25;
sendData.el = 10;
sendData.messageID = 1;
sendData.time = 100;
根据一些不同的教程,这对我来说看起来不错,但是在两台不同的机器上,编译时出现以下错误:
testserver.c:15:9: 错误: '=', ',', ';', 'asm' or ' attribute ' before '.' 令牌
testserver.c:16:9: 错误: '=', ',', ';', 'asm' or ' attribute ' before '.' 令牌
testserver.c:17:9: 错误: '=', ',', ';', 'asm' or ' attribute ' before '.' 令牌
testserver.c:18:9: 错误: '=', ',', ';', 'asm' or ' attribute ' before '.' 令牌
为什么我会收到此错误?
sendData.az = 25;
像这样的语句必须在 function 中。 如果要初始化结构,则有不同的语法:
struct RadarData sendData = { 25, 10, 1, 100 };
如果我正在查看您的代码(这是完整的相关代码),那么您将语句放在 function 之外。 那是不对的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.