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?

Community
  • 1
  • 1
Randomblue
  • 112,777
  • 145
  • 353
  • 547

1 Answers1

3

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

Paul Praet
  • 1,367
  • 14
  • 25
  • 1
    And what happens when it's not declared in a header? – San Jacinto May 01 '12 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 01 '12 at 16:54
  • My point was that this is something you should add to your answer. I don't think there's a guarantee in the standard that all pointer sizes are always the same, is there? – San Jacinto May 01 '12 at 16:56
  • 1
    Yes, all pointer sizes are always of the same size by definition. – Paul Praet May 03 '12 at 10:55
  • In practice, this is often true and I've never encountered anything different, but that does not mean that there's a guarantee. Please quote an authoritative source. See http://stackoverflow.com/questions/399003/is-the-sizeofsome-pointer-always-equal-to-four – San Jacinto May 03 '12 at 11:06
  • 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 03 '12 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. – San Jacinto May 03 '12 at 14:35