错误***没有名为***的成员

时间:2016-12-19 20:51:18

标签: c tcp structure

我不知道我做错了什么..

你有什么想法我做错了吗?结构在头文件sender.h中声明 - 代码

尝试编译此程序后,我收到此错误:

Sender/Sender.c: In function 'SenderCreate':
Sender/Sender.c:50: error: 'Sender' has no member named 'sim_buf'
Sender/Sender.c:51: error: 'Sender' has no member named 'sim_buf_length'
Sender/Sender.c: In function 'SenderExecuteTask':
Sender/Sender.c:75: error: 'sim_buf_length' undeclared (first use in this function)
Sender/Sender.c:75: error: (Each undeclared identifier is reported only once
Sender/Sender.c:75: error: for each function it appears in.)
Sender/Sender.c:77: error: 'sim_buf' undeclared (first use in this function)
make: *** [Sender.o] Error 1

以下程序代码:

#include <stdlib.h> // calloc, free
#include <stdio.h>
#include "Sender.h"
#include <fcntl.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <arpa/inet.h>
#include "../../rdo_module/readout_dev.h"

struct Sender_s {
    ET4DataSource *data_source;
    unsigned int num_of_images;
    unsigned int num_of_el;
    ConditionWait *condition_wait;
    int sock;
    struct sockaddr *PC;
    char *sim_buf;
    char *sim_buf_length;
};

void SenderSetNumOfEl(Sender *self, unsigned int num_of_el) {
    self->num_of_el = num_of_el;
}

Sender *
SenderCreate(ET4DataSource *data_source,
             unsigned int num_of_images,
             unsigned int num_of_el,
             ConditionWait *condition_wait,
             int sock,
             struct sockaddr *PC,
         char *sim_buf,                 // here I get some problems
         int *sim_buf_length)           // and here
{
    #ifdef DEBUG
        printf("Sender.c SenderCreate line 25: Sender *self = calloc(1, sizeof(Sender));\n");
    #endif

    Sender *self = calloc(1, sizeof(Sender));

    #ifdef DEBUG
        printf("Sender.c SenderCreate line 25: success\n");
    #endif

    self->data_source = data_source;
    self->num_of_images = num_of_images;
    self->num_of_el = num_of_el;
    self->condition_wait = condition_wait;
    self->sock = sock;
    self->PC = PC;
    self->sim_buf = sim_buf;
    self->sim_buf_length = sim_buf_length;

    return self;
}

void
SenderDestroy(Sender *self)
{
    free(self);
}

void *
SenderExecuteTask(void *self_)
{
    Sender *self = self_;
    ET4Buffer *buf = NULL;
    int n = 0;
    int c_len = sizeof(*(self->PC));

    while(1) {
            if(*sim_buf_length) {

                n=sendto(self->sock, sim_buf, *sim_buf_length, 0, self->PC, c_len);

                if(n < 0) {
                    perror("error in sendto()");
                    return NULL;
                }
    }

    return NULL;
}

下面的sender.h代码:

#ifndef __SENDER_H__
#define __SENDER_H__

#include <sys/socket.h>
#include <sys/select.h>
#include <arpa/inet.h>
#include "../Utils/ConditionWait.h"
#include "../DataSource/ET4DataSource.h"

typedef struct Sender_s Sender;

Sender *
SenderCreate(ET4DataSource *data_source,
             unsigned int num_of_images,
             unsigned int num_of_el,
             ConditionWait *condition_wait,
             int sock,
             struct sockaddr *PC,
         char *sim_buf,
         int *sim_buf_length);

void
SenderDestroy(Sender*self);

void *
SenderExecuteTask(void *self_);

void SenderSetNumOfEl(Sender *self, unsigned int num_of_el);

#endif /*__SENDER_MAKER_H__*/

1 个答案:

答案 0 :(得分:1)

错误消息和问题中的来源不匹配!

当我拿出给定的源时,编译器告诉我,错误。

  • 没有会员par("mar"),(请注意抱怨sim_buf_length
  • 收到错误消息“错误:'发件人'没有名为'sim_buf'的成员”,因为该成员显然存在
  • 此外,类型sim_buf_length_flag(Sender_s成员)和char*(SenderCreate参数)不匹配

函数int*的错误消息是明确的,没有变量声明SenderExecuteTasksim_buf。可能函数签名应该是

sim_buf_length(_flag)

然后分别使用定义void *SenderExecuteTask(Sender *self); self->sim_buf