linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Glynn Clements <glynn.clements@virgin.net>
To: linux-c-programming@vger.kernel.org
Subject: Re: dereferencing pointer to incomplete type
Date: Thu, 17 Jun 2004 11:24:51 +0100	[thread overview]
Message-ID: <16593.29043.16464.273595@cerise.nosuchdomain.co.uk> (raw)
In-Reply-To: <20040617042113.GE16146@luna.mooo.com>


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>

  parent reply	other threads:[~2004-06-17 10:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2004-06-17 17:03         ` Micha Feigin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16593.29043.16464.273595@cerise.nosuchdomain.co.uk \
    --to=glynn.clements@virgin.net \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).