From: Daniele Lugli <genlogic@inrete.it>
To: root@chaos.analogic.com, linux-kernel@vger.kernel.org
Subject: Re: unhappy with current.h
Date: Mon, 14 Oct 2002 23:22:26 +0200 [thread overview]
Message-ID: <3DAB3592.E19150C6@inrete.it> (raw)
In-Reply-To: Pine.LNX.3.95.1021014162539.16867B-100000@chaos.analogic.com
"Richard B. Johnson" wrote:
>
> On Mon, 14 Oct 2002, Daniele Lugli wrote:
>
> > I recently wrote a kernel module which gave me some mysterious problems.
> > After too many days spent in blood, sweat and tears, I found the cause:
> >
> > *** one of my data structures has a field named 'current'. ***
> >
> > Pretty common word, isn't it? Would you think it can cause such a
> > trouble? But in some of my files I happen to indirectly include
> > <asm/current.h> (kernel 2.4.18 for i386), containing the following line:
> >
> > #define current get_current()
> >
> > so that my structure becomes the owner of a function it has never asked
> > for, while it looses a data member. gcc has nothing to complain about
> > that.
> >
>
> This cannot be the reason for your problem. The name of a structure
> member has no connection whatsoever with the name of any function or
> definition.
>
> The following code will correctly write "Hello world!" to the screen
> even though the text initializes a member of a structure called "current"
> while "current" has been defined to be a function called puts.
>
> #include <stdio.h>
> #define current puts
> struct foo {
> char *current;
> int foo;
> } bar;
> main()
> {
> bar.current = "Hello world!";
> current(bar.current);
> return 0;
> }
>
> For your code to get "confused", you really have something else
> wrong. That said, some name-space polution may make it difficult
> to find the problem. For instance, a structure member is expected
> to have a ";" after it. It's possible for some previous definition
> to make a syntax error invisible.
>
> Cheers,
> Dick Johnson
Try the following instead:
// file shade1.cpp
// excerpt from common.h
#define current get_current()
// my stuff
struct {
int any;
int current[1000];
} mine;
// file shade2.cpp
#include <stdio.h>
// my stuff
extern struct {
int any;
int current[1000];
} mine;
int main () {
mine.current[999] = 1;
printf ("%d\n", mine.current[999]);
}
g++ shade1.cpp shade2.cpp
./a.out => segmentation fault
Regards, Daniele
next prev parent reply other threads:[~2002-10-14 21:16 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-14 19:46 unhappy with current.h Daniele Lugli
2002-10-14 19:52 ` David S. Miller
2002-10-14 20:18 ` Daniele Lugli
2002-10-14 20:24 ` Chris Wedgwood
2002-10-15 0:00 ` Rik van Riel
2002-10-15 1:05 ` Chris Wedgwood
2002-10-15 1:12 ` Murray J. Root
2002-10-15 14:11 ` Mikael Pettersson
2002-10-15 20:29 ` Daniele Lugli
2002-10-15 20:44 ` Alexander Viro
2002-10-15 21:01 ` Mikael Pettersson
2002-10-14 20:33 ` Richard B. Johnson
2002-10-14 20:33 ` David S. Miller
2002-10-14 20:37 ` Olivier Galibert
2002-10-15 18:31 ` Richard B. Johnson
2002-10-14 21:22 ` Daniele Lugli [this message]
2002-10-15 17:08 ` Richard B. Johnson
2002-10-14 20:45 ` Andi Kleen
2002-10-15 1:09 ` Chris Wedgwood
[not found] <20021014.161535.17120.336861@webmail4.nyc.untd.com>
2002-10-14 20:24 ` Daniele Lugli
-- strict thread matches above, loose matches on Subject: below --
2002-10-18 14:49 Jeffrey Lim
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=3DAB3592.E19150C6@inrete.it \
--to=genlogic@inrete.it \
--cc=linux-kernel@vger.kernel.org \
--cc=root@chaos.analogic.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