使用结构时出现编译器错误

问题描述 投票:0回答:2

我在初始化结构时遇到奇怪的编译器错误。

#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”或“attribute” testserver.c:16:9:错误:在“.”标记之前需要“=”、“,”、“;”、“asm”或“
attribute” testserver.c:17:9:错误:在“.”标记之前需要“=”、“,”、“;”、“asm”或“attribute
” testserver.c:18:9:错误:在“.”标记之前需要“=”、“,”、“;”、“asm”或“attribute
为什么我会收到此错误?

sendData.az = 25;

c compiler-errors
2个回答
9
投票
struct RadarData sendData = { 25, 10, 1, 100 };

如果我正确地查看了您的代码(这是完整的相关代码),那么您将语句放置在函数之外。这是不对的。

3
投票

© www.soinside.com 2019 - 2024. All rights reserved.