From: Andrew Morton <akpm@osdl.org>
To: David Brownell <david-b@pacbell.net>
Cc: "Thiago Galesi" <thiagogalesi@gmail.com>,
"Andrea Paterniani" <a.paterniani@swapp-eng.it>,
"Linux Kernel list" <linux-kernel@vger.kernel.org>
Subject: Re: [patch 2.6.18-git] SPI -- Freescale iMX SPI controller driver
Date: Mon, 2 Oct 2006 13:38:06 -0700 [thread overview]
Message-ID: <20061002133806.10bd652d.akpm@osdl.org> (raw)
In-Reply-To: <200610021310.15374.david-b@pacbell.net>
On Mon, 2 Oct 2006 13:10:14 -0700
David Brownell <david-b@pacbell.net> wrote:
> > > +/* Message state */
> > > +#define START_STATE ((void*)0)
> > > +#define RUNNING_STATE ((void*)1)
> > > +#define DONE_STATE ((void*)2)
> > > +#define ERROR_STATE ((void*)-1)
> >
> > !?!??!?!
>
> Now that you mention it ... let me second that comment!
These are "better enums". The problem with C's enums is that it's possible
to mix them with integers and the compiler just swallows it. With the
above, you'll get a warning if you make that mistake.
But otoh, it's possible to accidentally mix the above with, say, char*.
And it's not convenient to declare this type. So something like this would
be better:
struct not_a_struct {};
typedef struct not_a_struct *better_enum;
#define RUNNING_STATE ((better_enum)1)
better_enum my_function(better_enum b)
{
...
return RUNNING_STATE;
}
would work.
Next would be
#define DECLARE_BETTER_ENUM(name) \
struct not_a_struct_##name {}; \
typedef struct not_a_struct##name better_enum_##name;
so we can declare types like better_enum_spi_state,
better_enum_notifier_return_, etc.
Anyway, back to work... any patch which actually attempts to implement
this sort of thing will be cheerily ignored ;) Do the enum-mismatch checking
in sparse.
next prev parent reply other threads:[~2006-10-02 20:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-02 15:16 [patch 2.6.18-git] SPI -- Freescale iMX SPI controller driver David Brownell
2006-10-02 17:59 ` Andrew Morton
2006-10-02 20:16 ` David Brownell
2006-10-03 16:08 ` Andrea Paterniani
2006-10-06 23:35 ` David Brownell
2006-10-07 11:01 ` Andrea Paterniani
2006-10-07 23:50 ` David Brownell
2006-10-02 18:37 ` Thiago Galesi
2006-10-02 20:10 ` David Brownell
2006-10-02 20:38 ` Andrew Morton [this message]
2006-10-02 21:09 ` David Brownell
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=20061002133806.10bd652d.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=a.paterniani@swapp-eng.it \
--cc=david-b@pacbell.net \
--cc=linux-kernel@vger.kernel.org \
--cc=thiagogalesi@gmail.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