* dereferencing pointer to incomplete type
@ 2004-06-16 19:56 Anshuman S. Rawat
2004-06-16 20:14 ` Christoph Bussenius
2004-06-16 22:01 ` Micha Feigin
0 siblings, 2 replies; 10+ messages in thread
From: Anshuman S. Rawat @ 2004-06-16 19:56 UTC (permalink / raw)
To: linux-c-programming
Hi,
I got the following error while compiling some module -
Arping.xs:153: dereferencing pointer to incomplete type
make: *** [Arping.o] Error 1
Now line 153 in the source is -
memcpy(enet_src, src_mac->ether_addr_octet,6);
where
u_char enet_src[6] = {0x00, 0x00, 0x00, 0x00, 0x00,0x00};
struct ether_addr *src_mac;
struct ether_addr
{
u_char ether_addr_octet[6];
};
are the definitions.
I haven't been able to figure out what the problem is.
Any help will be appreciated.
Thanks.
Anshuman
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: dereferencing pointer to incomplete type 2004-06-16 19:56 dereferencing pointer to incomplete type Anshuman S. Rawat @ 2004-06-16 20:14 ` Christoph Bussenius 2004-06-16 20:13 ` Anshuman S. Rawat 2004-06-16 22:01 ` Micha Feigin 1 sibling, 1 reply; 10+ messages in thread From: Christoph Bussenius @ 2004-06-16 20:14 UTC (permalink / raw) To: linux-c-programming On Wed, Jun 16, 2004 at 03:56:37PM -0400, Anshuman S. Rawat wrote: > Arping.xs:153: dereferencing pointer to incomplete type > make: *** [Arping.o] Error 1 > > memcpy(enet_src, src_mac->ether_addr_octet,6); ... > struct ether_addr > { > u_char ether_addr_octet[6]; > }; Hi, I think you should define that struct _before_ you use it. This error is exactly what you get when you define it later. HTH, Christoph -- ``There's no dark side of the moon, really Matter of fact, it's all dark'' --Pink Floyd ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: dereferencing pointer to incomplete type 2004-06-16 20:14 ` Christoph Bussenius @ 2004-06-16 20:13 ` Anshuman S. Rawat 2004-06-16 21:04 ` Glynn Clements 0 siblings, 1 reply; 10+ messages in thread From: Anshuman S. Rawat @ 2004-06-16 20:13 UTC (permalink / raw) To: Christoph Bussenius, linux-c-programming > On Wed, Jun 16, 2004 at 03:56:37PM -0400, Anshuman S. Rawat wrote: > > Arping.xs:153: dereferencing pointer to incomplete type > > make: *** [Arping.o] Error 1 > > > > memcpy(enet_src, src_mac->ether_addr_octet,6); > ... > > struct ether_addr > > { > > u_char ether_addr_octet[6]; > > }; > > Hi, I think you should define that struct _before_ you use it. This > error is exactly what you get when you define it later. The struct is defined before it is used through a header file. I just wrote it afterwards here to show what it was. Thanks. -Anshuman > > HTH, > Christoph > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: dereferencing pointer to incomplete type 2004-06-16 20:13 ` Anshuman S. Rawat @ 2004-06-16 21:04 ` Glynn Clements 0 siblings, 0 replies; 10+ messages in thread From: Glynn Clements @ 2004-06-16 21:04 UTC (permalink / raw) To: Anshuman S. Rawat; +Cc: linux-c-programming Anshuman S. Rawat wrote: > > > Arping.xs:153: dereferencing pointer to incomplete type In the absence of any other errors, this usually means that you are dereferencing a pointer to a structure or union type, but the compiler doesn't have the definition of the structure. This is normally only relevant to struct/union types, as it is possible to refer to undefined struct/union types without a syntax error, i.e. struct foo *p; union bar *q; Attempting to use any other unknown type, e.g. foo *p; would result in a syntax error (e.g. "parse error before '*' token"). However, any operation which requires the actual definition of those structures (i.e. accessing fields with -> or performing pointer arithmetic) will generate the above "incomplete type" error unless the definitions are known. > > > make: *** [Arping.o] Error 1 > > > > > > memcpy(enet_src, src_mac->ether_addr_octet,6); > > ... > > > struct ether_addr > > > { > > > u_char ether_addr_octet[6]; > > > }; > > > > Hi, I think you should define that struct _before_ you use it. This > > error is exactly what you get when you define it later. > > The struct is defined before it is used through a header file. The error message indicates that the compiler doesn't know the definition of "struct ether_addr", which suggests that it hasn't actually been defined (e.g. because the relevant header file (net/ethernet.h) hasn't been included). -- Glynn Clements <glynn.clements@virgin.net> ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: dereferencing pointer to incomplete type 2004-06-16 19:56 dereferencing pointer to incomplete type Anshuman S. Rawat 2004-06-16 20:14 ` Christoph Bussenius @ 2004-06-16 22:01 ` Micha Feigin 2004-06-16 23:02 ` Anshuman S. Rawat 1 sibling, 1 reply; 10+ messages in thread From: Micha Feigin @ 2004-06-16 22:01 UTC (permalink / raw) To: linux-c-programming On Wed, Jun 16, 2004 at 03:56:37PM -0400, Anshuman S. Rawat wrote: > Hi, > I got the following error while compiling some module - > > Arping.xs:153: dereferencing pointer to incomplete type > make: *** [Arping.o] Error 1 > > > Now line 153 in the source is - > > memcpy(enet_src, src_mac->ether_addr_octet,6); > > where > > u_char enet_src[6] = {0x00, 0x00, 0x00, 0x00, 0x00,0x00}; > > struct ether_addr *src_mac; > > > struct ether_addr > { > u_char ether_addr_octet[6]; > }; > > are the definitions. > > I haven't been able to figure out what the problem is. > Any help will be appreciated. > Try as a test to add the struct definition just before the call to memcpy and see if that resolves the error. Could be that for some reason things aren't included properly. > Thanks. > Anshuman > > > - > To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > > +++++++++++++++++++++++++++++++++++++++++++ > This Mail Was Scanned By Mail-seCure System > at the Tel-Aviv University CC. > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: dereferencing pointer to incomplete type 2004-06-16 22:01 ` Micha Feigin @ 2004-06-16 23:02 ` Anshuman S. Rawat 2004-06-17 4:21 ` Micha Feigin 0 siblings, 1 reply; 10+ messages in thread From: Anshuman S. Rawat @ 2004-06-16 23:02 UTC (permalink / raw) To: Micha Feigin, linux-c-programming > > Arping.xs:153: dereferencing pointer to incomplete type > > make: *** [Arping.o] Error 1 > > > > Now line 153 in the source is - > > > > memcpy(enet_src, src_mac->ether_addr_octet,6); > > where > > u_char enet_src[6] = {0x00, 0x00, 0x00, 0x00, 0x00,0x00}; > > struct ether_addr *src_mac; > > struct ether_addr > > { > > u_char ether_addr_octet[6]; > > }; > > Try as a test to add the struct definition just before the call to > memcpy and see if that resolves the error. Could be that for some > reason things aren't included properly. I already tried this. It didn't help. -Anshuman ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: dereferencing pointer to incomplete type 2004-06-16 23:02 ` Anshuman S. Rawat @ 2004-06-17 4:21 ` Micha Feigin 2004-06-17 8:46 ` Christoph Bussenius 2004-06-17 10:24 ` Glynn Clements 0 siblings, 2 replies; 10+ messages in thread From: Micha Feigin @ 2004-06-17 4:21 UTC (permalink / raw) To: linux-c-programming On Wed, Jun 16, 2004 at 07:02:04PM -0400, Anshuman S. Rawat wrote: > > > Arping.xs:153: dereferencing pointer to incomplete type > > > make: *** [Arping.o] Error 1 > > > > > > Now line 153 in the source is - > > > > > > memcpy(enet_src, src_mac->ether_addr_octet,6); > > > where > > > u_char enet_src[6] = {0x00, 0x00, 0x00, 0x00, 0x00,0x00}; > > > struct ether_addr *src_mac; > > > struct ether_addr > > > { > > > u_char ether_addr_octet[6]; > > > }; > > > > Try as a test to add the struct definition just before the call to > > memcpy and see if that resolves the error. Could be that for some > > reason things aren't included properly. > > I already tried this. It didn't help. > In this case its probably something else. Are you sure that u_char is properly defined? what happens if you add before the these definitions? typedef unsigned char * u_char; or write: memcpy((void *)enet_src, (void *)(src_mac->ether_addr_octet), 6); or just to make sure we are looking at the right thing to do memcpy(enet_src, enet_src, 6); BTW, what is the .xs file sufix? > -Anshuman > > > - > To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > > +++++++++++++++++++++++++++++++++++++++++++ > This Mail Was Scanned By Mail-seCure System > at the Tel-Aviv University CC. > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: dereferencing pointer to incomplete type 2004-06-17 4:21 ` Micha Feigin @ 2004-06-17 8:46 ` Christoph Bussenius 2004-06-17 10:24 ` Glynn Clements 1 sibling, 0 replies; 10+ messages in thread From: Christoph Bussenius @ 2004-06-17 8:46 UTC (permalink / raw) To: linux-c-programming > BTW, what is the .xs file sufix? Hi Micha, XS is an interface to write modules for Perl in C. Regards, Christoph -- ``There's no dark side of the moon, really Matter of fact, it's all dark'' --Pink Floyd ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: dereferencing pointer to incomplete type 2004-06-17 4:21 ` Micha Feigin 2004-06-17 8:46 ` Christoph Bussenius @ 2004-06-17 10:24 ` Glynn Clements 2004-06-17 17:03 ` Micha Feigin 1 sibling, 1 reply; 10+ messages in thread From: Glynn Clements @ 2004-06-17 10:24 UTC (permalink / raw) To: linux-c-programming Micha Feigin wrote: > > > > Arping.xs:153: dereferencing pointer to incomplete type > In this case its probably something else. I doubt it. > Are you sure that u_char is properly defined? If it wasn't, attempts to define variables or structure fields of type u_char would result in a parse error. An "incomplete type" error has to refer to a struct, union or enum (ANSI C forbids forward references to enum types, but gcc allows it). These are the only cases where the compiler can know that something is a type without knowing the type's definition. I'm quite certain that the problem is due to the fact that the compiler knows that src_mac is a pointer to "struct ether_addr" but doesn't know the definition of "struct ether_addr". As the error message says: Arping.xs:153: dereferencing pointer to incomplete type Assuming that the poster is correct in stating that line 153 is: memcpy(enet_src, src_mac->ether_addr_octet,6); the only dereference in that line is "src_mac->ether_addr_octet", and the pointer is "src_mac". So, the message is stating that src_mac has "incomplete" type, which means that the compiler knows that it is a struct, but doesn't know its definition (in particular, it doesn't know the offset of the ether_addr_octet field, so it cannot compile the expression). For the record, the compiler wouldn't be concerned if enet_src had incomplete type, because it isn't being dereferenced. The following source file compiles without any errors or warnings (even with "-ansi -pedantic -Wall"): #include <string.h> #include <net/ethernet.h> extern struct foo *enet_src; extern struct ether_addr *src_mac; void foo(void) { memcpy(enet_src, src_mac->ether_addr_octet,6); } In summary, I strongly suspect that the .xs file isn't producing the C code which the author expects; specifically, that the definition for "struct ether_addr" isn't being seen. -- Glynn Clements <glynn.clements@virgin.net> ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: dereferencing pointer to incomplete type 2004-06-17 10:24 ` Glynn Clements @ 2004-06-17 17:03 ` Micha Feigin 0 siblings, 0 replies; 10+ messages in thread From: Micha Feigin @ 2004-06-17 17:03 UTC (permalink / raw) To: linux-c-programming On Thu, Jun 17, 2004 at 11:24:51AM +0100, Glynn Clements wrote: > > Micha Feigin wrote: > > > > > > Arping.xs:153: dereferencing pointer to incomplete type > > > In this case its probably something else. > > I doubt it. > > > Are you sure that u_char is properly defined? > > If it wasn't, attempts to define variables or structure fields of type > u_char would result in a parse error. > > An "incomplete type" error has to refer to a struct, union or enum > (ANSI C forbids forward references to enum types, but gcc allows it). > These are the only cases where the compiler can know that something is > a type without knowing the type's definition. > > I'm quite certain that the problem is due to the fact that the > compiler knows that src_mac is a pointer to "struct ether_addr" but > doesn't know the definition of "struct ether_addr". > > As the error message says: > > Arping.xs:153: dereferencing pointer to incomplete type > > Assuming that the poster is correct in stating that line 153 is: > > memcpy(enet_src, src_mac->ether_addr_octet,6); > Thus my suggestion to change src_mac->ether_addr_octet to enet_src, it obviously does the wrong thing but should kill the error message if we are looking at the right line. > the only dereference in that line is "src_mac->ether_addr_octet", and > the pointer is "src_mac". So, the message is stating that src_mac has > "incomplete" type, which means that the compiler knows that it is a > struct, but doesn't know its definition (in particular, it doesn't > know the offset of the ether_addr_octet field, so it cannot compile > the expression). > > For the record, the compiler wouldn't be concerned if enet_src had > incomplete type, because it isn't being dereferenced. The following > source file compiles without any errors or warnings (even with "-ansi > -pedantic -Wall"): > > #include <string.h> > #include <net/ethernet.h> > > extern struct foo *enet_src; > extern struct ether_addr *src_mac; > > void foo(void) > { > memcpy(enet_src, src_mac->ether_addr_octet,6); > } > > In summary, I strongly suspect that the .xs file isn't producing the C > code which the author expects; specifically, that the definition for > "struct ether_addr" isn't being seen. > That seems that way, but when I suggested adding the definition in the file just before the call the OP said that he tried that and it didn't solve the problem. > -- > Glynn Clements <glynn.clements@virgin.net> > - > To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > > +++++++++++++++++++++++++++++++++++++++++++ > This Mail Was Scanned By Mail-seCure System > at the Tel-Aviv University CC. > ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2004-06-17 17:03 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2004-06-16 19:56 dereferencing pointer to incomplete type Anshuman S. Rawat 2004-06-16 20:14 ` Christoph Bussenius 2004-06-16 20:13 ` Anshuman S. Rawat 2004-06-16 21:04 ` Glynn Clements 2004-06-16 22:01 ` Micha Feigin 2004-06-16 23:02 ` Anshuman S. Rawat 2004-06-17 4:21 ` Micha Feigin 2004-06-17 8:46 ` Christoph Bussenius 2004-06-17 10:24 ` Glynn Clements 2004-06-17 17:03 ` Micha Feigin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).