From: Micha Feigin <michf@post.tau.ac.il>
To: linux-c-programming@vger.kernel.org
Subject: Re: dereferencing pointer to incomplete type
Date: Thu, 17 Jun 2004 20:03:38 +0300 [thread overview]
Message-ID: <20040617170338.GG19531@luna.mooo.com> (raw)
In-Reply-To: <16593.29043.16464.273595@cerise.nosuchdomain.co.uk>
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.
>
prev parent reply other threads:[~2004-06-17 17:03 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
2004-06-17 17:03 ` Micha Feigin [this message]
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=20040617170338.GG19531@luna.mooo.com \
--to=michf@post.tau.ac.il \
--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).