1

I want to call a function low_level_init which has signature

void low_level_init(struct netif *netif)

I have tried

struct netif dummy;
low_level_init(&dummy);

but I get the error

storage size of 'dummy' isn't known

I have also tried (as suggested here)

extern struct netif dummy;
low_level_init(&dummy);

but then I get the error

error: 'dummy' undeclared (first use in this function)

How can I call low_level_init?

2
  • You need to give a definition for struct netif, perhaps it's in a header you forgot to include? May 1, 2012 at 16:51
  • Add #include <net/if.h> to the end of the "include" section at the top of your file. It should come after all other headers; the problem should go away. May 1, 2012 at 16:57

1 Answer 1

3

Include the header file where that structure is defined. Otherwise the compiler cannot know how much space to reserve.

7
  • 1
    And what happens when it's not declared in a header? May 1, 2012 at 16:52
  • 1
    You CAN declare a pointer to an undefined struct (as sizes of pointers are always the same), but you cannot declare a variable of an undefined type. It just can't work.
    – Paul Praet
    May 1, 2012 at 16:54
  • 1
    Yes, all pointer sizes are always of the same size by definition.
    – Paul Praet
    May 3, 2012 at 10:55
  • 1
    Of course there can be differences between pointer sizes on different systems, but on the SAME system, pointers have the same size. Just check K&R if you want...
    – Paul Praet
    May 3, 2012 at 13:52
  • 1
    K&R is not the standard. But beyond that, you're missing the point of the accepted answer on that other question. There are some people commenting on that answer that I would regard as C and C++ experts who did not correct it. Read the first line. One of the two of your is wrong. I'm asking for you to quote an authoritative source. If you don't want to, that's cool. Just don't act like you are discussing facts when you're discussing your working experience. May 3, 2012 at 14:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.