From: cgd@broadcom.com
To: zack@codesourcery.com
Cc: gdb@sources.redhat.com, gcc@sources.redhat.com
Subject: Re: Suggestion: Detect inconsistent structure definitions
Date: Wed, 13 Mar 2002 18:35:00 -0000 [thread overview]
Message-ID: <yov5pu2798ri.fsf@broadcom.com> (raw)
In-Reply-To: zack@codesourcery.com's message of "Wed, 13 Mar 2002 18:22:41 +0000 (UTC)"
At Wed, 13 Mar 2002 18:22:41 +0000 (UTC), "Zack Weinberg" wrote:
> Consider the following two source files:
>
> -- a.c --
> struct A {
> int a;
> int b;
> };
>
> struct A a = { 1, 2 };
>
> -- b.c --
> struct A {
> char a;
> char b;
> };
>
> extern struct A a;
>
> int main(void) {
> if (a.a == 1 && b.a == 2)
> return 0;
> else
> return 1;
> }
>
> --
> It is obvious that the complete program consisting of these two files
> is buggy: the declarations of struct A do not match. However, the
> program will compile, link, and execute with no complaints, just an
> unexpected return value.
>
> When the program is large and complicated, this sort of bug can be
> near-impossible to find, especially when the structure type
> declaration _is_ properly isolated in a header file, but other headers
> (possibly from third-party libraries) have issued inconsistent
> typedefs/#defines for the aggregate's member types. I just spent two
> days chasing exactly this problem in an INN installation.
>
> The compiler and linker do not have enough information to detect the
> bug, but gdb does [ ... ]
I believe that this type of bug will typically be discovered by proper
application of 'lint'.
There are open-source versions of lint out there... (I dunno what
OSes ship them, but NetBSD definitely does.)
If you want to solve this problem in the context of the gcc and
related tools, my personal thought as to "the right thing" would be to
create a mode for gcc which can output lint-like information instead
of object code, and then create an external program to merge that
information.
(this is what lint does: in the first 'pass' it has a C parser, etc.,
and parses the C code and can output lint files (instead of .o files).
then, another pass merges that all together and produces final results
/ warnings.)
If you did the first pass inside GCC, you might even be able to do it
so that it would even work/interoperate for languages other than C.
8-)
chris
prev parent reply other threads:[~2002-03-14 2:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-03-13 10:22 Zack Weinberg
2002-03-13 10:40 ` Kris Warkentin
2002-03-13 16:02 ` Daniel Jacobowitz
2002-03-14 5:14 ` Kris Warkentin
2002-03-13 16:07 ` Daniel Jacobowitz
2002-03-14 11:13 ` Zack Weinberg
2002-03-14 21:03 ` Daniel Jacobowitz
2002-03-14 22:11 ` Andrew Cagney
[not found] ` <mailpost.1016043761.7328@news-sj1-1>
2002-03-13 18:35 ` cgd [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=yov5pu2798ri.fsf@broadcom.com \
--to=cgd@broadcom.com \
--cc=gcc@sources.redhat.com \
--cc=gdb@sources.redhat.com \
--cc=zack@codesourcery.com \
/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