1

I have two typedefs for function pointers and two structs, struct pipe_s and struct pipe_buffer_s defined as so:

typedef void (*pipe_inf_t)(struct pipe_buffer_s *);
typedef void (*pipe_outf_t)(struct pipe_buffer_s *);

struct
pipe_buffer_s
{
    size_t cnt;      /* number of chars in buffer */
    size_t len;      /* length of buffer */
    uint8_t *mem;    /* buffer */
};

struct
pipe_s
{
    struct pipe_buffer_s buf;
    uint8_t state;
    pipe_inf_t in;   /* input call */
    pipe_outf_t out; /* output call */
};

In my implementation, I have a function that attempts to call the function in:

void
pipe_receive(struct pipe_s *pipe)
{
    pipe_inf_t in;
    in = pipe->in;
    in(&pipe->buf);
}

But I am getting the strange error:

pipe.c:107:5: note: expected 'struct pipe_buffer_s *' but argument is of type 'struct pipe_buffer_s *'

This makes no sense to me. As far as I can tell, I haven't goofed up and tried to use a struct of undefined length because I'm only using pointers here. I think I may have done something wrong with my typedef...

Changing the typedef to typedef void (*pipe_inf_t)(int); and calling in(5) works just fine however.

I get the same error if I move in and out into the pipe_buffer_s struct and call them from there so location doesn't seem to matter.

Any ideas?

4
  • @wildplasser I'm writing an OS in ANSI C. It's gcc with std=c89. Commented Feb 16, 2021 at 11:00
  • 1
    You'll need an opaque pointer before the pointer typedefs. Or change the order. Commented Feb 16, 2021 at 11:03
  • 1
    Is that the only warning or error you get? I get more than that. All the errors are fixed by moving the typedefs to be after struct pipe_buffer_s as the typedefs need that struct definition. Commented Feb 16, 2021 at 11:04
  • @kaylum Oh my gosh, you're absolutely right, that's what fixed it. Commented Feb 16, 2021 at 11:06

1 Answer 1

2

Add the definition of pipe_buffer_s before referring to it. This can be an incomplete type:


#include <stdlib.h>
#include <stdint.h>

struct pipe_buffer_s; // Incomplete definition

typedef void (*pipe_inf_t)(struct pipe_buffer_s *);
typedef void (*pipe_outf_t)(struct pipe_buffer_s *);

struct
pipe_buffer_s
{
    size_t cnt;      /* number of chars in buffer */
    size_t len;      /* length of buffer */
    uint8_t *mem;    /* buffer */
};

struct
pipe_s
{
    struct pipe_buffer_s buf;
    uint8_t state;
    pipe_inf_t in;   /* input call */
    pipe_outf_t out; /* output call */
};

// In my implementation, I have a function that attempts to call the function in:

void
pipe_receive(struct pipe_s *pipe)
{
    pipe_inf_t in;
    in = pipe->in;
    in(&pipe->buf);
}
Sign up to request clarification or add additional context in comments.

1 Comment

That is indeed the case. I may have had it well defined but I didn't have it defined quick enough... Thank you very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.