Re: Stupid question about c structures



It was a stupid error on my side.
Problem solved

In one case the definition was available, in the other it wasn't :)


On Mon, 10 Sep 2007 11:39:30 -0600, Joe Pfeiffer wrote:

Josef Moellers <josef.moellers@xxxxxxxxxxxxxxxxxxx> writes:

Guenther Sohler wrote:
I want to declare a variable of type sockaddr_in
If I declare it plain into a c function
struct sockaddr_in server;
it works, fine
But if i place it inside a structure
it always complains
error: field 'server' has incomplete type

#include <netinet/in.h>

> whats the trick ?

The "trick" is, that you can define something as being a "struct
sockaddr_in" without telling what it actually looks like. You can then
declare pointers to this structure and cast between pointers of a
different type (e.g. struct sockaddr) and this pointer, but you cannot
declare a variable of this type or access any of its members.

If his question includes the actual declaration he's trying to make,
it isn't a pointer...

.



Relevant Pages

  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... In the header we would declare? ...
    (microsoft.public.vc.language)
  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... It also returned the value of the pointer. ...
    (microsoft.public.vc.language)
  • Re: Is declaring a pointer to an undefined struct legal?
    ... >>it to declare pointers to this struct for which no definition is in ... >>scope and to pass those pointers into functions declared in that header? ... > which does have a declaration for the struct type in scope; ...
    (comp.lang.c)
  • Re: IAR linker: too smart
    ... I am using the IAR toolchain for our Renesas M16C based project. ... The compiler is doing exactly the right thing - if you declare variables that are never used, then the compiler and/or linker is free to remove them - they have no effect on the running of your program. ... define a big struct which contains all variables and put that struct into E2PROM_DATA ...
    (comp.arch.embedded)
  • Re: Passing an array of structuresfrom a pointer?
    ... an array of struct. ... You cannot assign a pointer to struct to a long* ... to only declare structs in headers and then define the ...
    (microsoft.public.vc.language)