From: Anton Altaparmakov <aia21@cam.ac.uk>
To: Linus Torvalds <torvalds@osdl.org>
Cc: viro@parcelfarce.linux.theplanet.co.uk,
Andrew Morton <akpm@osdl.org>,
linux-kernel@vger.kernel.org,
linux-ntfs-dev@lists.sourceforge.net
Subject: Re: [PATCH 8/10] Re: [2.6-BK-URL] NTFS: 2.1.19 sparse annotation, cleanups and a bugfix
Date: Sun, 26 Sep 2004 08:47:30 +0100 (BST) [thread overview]
Message-ID: <Pine.LNX.4.60.0409260828200.18239@hermes-1.csi.cam.ac.uk> (raw)
In-Reply-To: <Pine.LNX.4.58.0409241930510.2317@ppc970.osdl.org>
On Fri, 24 Sep 2004, Linus Torvalds wrote:
> On Fri, 24 Sep 2004, Anton Altaparmakov wrote:
> > On Fri, 24 Sep 2004, Linus Torvalds wrote:
> > >
> > > Btw, Al is fixing this. We'll make enum's properly typed, rather than just
> > > plain integers. It's not traditional C behaviour, but it gives you better
> > > type safety, and Al points out that other C compilers (the Plan 9 one, to
> > > be specific) have done the same thing for similar reasons.
>
> Well, when I said "Al is fixing this", I lied.
>
> I just fixed it myself.
Great. (-:
> > This is good news. Once that is done I will be very happy to go back to
> > using enums as I also agree that they can and in this case do look a
> > lot nicer...
>
> Try the current sparse, I think it should work for you.
>
> So if you make an enum where the initializer expression is a little-endian
> expression, the type of that (single) enumerator will be little-endian.
>
> HOWEVER, the type of an enum _variable_ will still be just "int". So
>
> enum myenum {
> one = 1ULL,
> two = 2,
> };
>
> has the strange behaviour that if you use "one" in an expression, it will
> have the type "unsigned long long", but if you use a "enum myenum" entry
> (even if it has the value "1"), it will be an "int":
>
> sizeof(one) == 8
> sizeof(enum myenum) == 4
>
> So I would stronly suggest (and I may make sparse warn) against using
> non-integertyped enum values with any enum that actually has any backing
> store (ie if you ever use a variable of type "enum myenum", that would
> result in a warning - you can really just use the values "one" and "two"
> directly).
Ah, I was using them for backing store as well and I was using the
__attribute__((packed)) gcc extension to make them the bit-width I wanted
in combination with a "filler element" at the end of the enum.
So for example to get a 16-bit enum type I was using:
typedef enum {
RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002),
REST_AREA_SPACE_FILLER = 0xffff /* Just to make flags
16-bit. */
} __attribute__ ((__packed__)) RESTART_AREA_FLAGS;
And then when defining the structure containing these flags I would just
do:
typedef struct {
...
RESTART_AREA_FLAGS flags;
...
} __attribute__ ((__packed__)) RESTART_AREA;
Also I use the enum type as parameters to functions, for example in the
above case I might have:
int blah(RESTART_AREA_FLAGS flags);
So this use doesn't work with the sparse update either. At the moment I
have changed everything to just a bunch of #defines followed by a:
typedef le16 RESTART_AREA_FLAGS;
So I guess with your sparse update I can now go to a point in between the
old one and the new one:
enum {
RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002),
} __attribute__ ((__packed__)) RESTART_AREA_FLAGS;
typedef le16 RESTART_AREA_FLAGS;
So I get the enum rather than bunch of defines and I get my proper types
as well.
That only looses the ability for the compiler to warn if people use the
wrong constant when trying to set such a variable or pass a wrong constant
into a function but that is not nearly as useful a warning as the wrong
endianness bitwise warnings we have now gained so I am not going to worry
about losing it.
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
next prev parent reply other threads:[~2004-09-26 7:47 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-24 16:11 [2.6-BK-URL] NTFS: 2.1.19 sparse annotation, cleanups and a bugfix Anton Altaparmakov
2004-09-24 16:12 ` [PATCH 1/10] " Anton Altaparmakov
2004-09-24 16:12 ` [PATCH 2/10] " Anton Altaparmakov
2004-09-24 16:13 ` [PATCH 3/10] " Anton Altaparmakov
2004-09-24 16:13 ` [PATCH 4/10] " Anton Altaparmakov
2004-09-24 16:13 ` [PATCH 5/10] " Anton Altaparmakov
2004-09-24 16:13 ` [PATCH 6/10] " Anton Altaparmakov
2004-09-24 16:14 ` [PATCH 7/10] " Anton Altaparmakov
2004-09-24 16:14 ` [PATCH 8/10] " Anton Altaparmakov
2004-09-24 16:15 ` [PATCH 9/10] " Anton Altaparmakov
2004-09-24 16:15 ` [PATCH 10/10] " Anton Altaparmakov
2004-09-24 16:30 ` [PATCH 8/10] " Linus Torvalds
2004-09-24 20:02 ` Anton Altaparmakov
2004-09-25 2:46 ` Linus Torvalds
2004-09-25 7:25 ` viro
2004-09-25 15:43 ` Linus Torvalds
2004-09-26 7:48 ` Anton Altaparmakov
2004-09-26 16:39 ` Linus Torvalds
2004-09-26 7:47 ` Anton Altaparmakov [this message]
2004-09-26 7:51 ` Anton Altaparmakov
2004-09-25 6:38 ` [PATCH 7/10] " viro
2004-09-25 23:31 ` Anton Altaparmakov
2004-09-25 6:35 ` [PATCH 6/10] " viro
2004-09-25 23:09 ` Anton Altaparmakov
2004-09-26 0:10 ` Anton Altaparmakov
2004-09-25 6:32 ` [PATCH 4/10] " viro
2004-09-26 0:06 ` Anton Altaparmakov
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=Pine.LNX.4.60.0409260828200.18239@hermes-1.csi.cam.ac.uk \
--to=aia21@cam.ac.uk \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-ntfs-dev@lists.sourceforge.net \
--cc=torvalds@osdl.org \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
/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).