git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Nicolas Pitre <nico@cam.org>
Cc: Junio C Hamano <junkio@cox.net>, git@vger.kernel.org
Subject: Re: [PATCH 5/6] convert object type handling from a string to a number
Date: Tue, 27 Feb 2007 08:24:32 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0702270816350.12485@woody.linux-foundation.org> (raw)
In-Reply-To: <alpine.LRH.0.82.0702270856360.29426@xanadu.home>



On Tue, 27 Feb 2007, Nicolas Pitre wrote:
> > 
> > I am wondering if "enum object_type" and signed comparison here
> > are compatible.
> 
> Enums are signed as far as I know.

No they are not.

"enums" are traditionally "int", but it's not a requirement, and the 
technical C requirement is that they be "an integral size sufficiently 
large to hold all the possible values".

In other words, with a small set of values, it's entirely possible that 
the integral type in question be "unsigned char", for example.

It so happens that gcc will never *by*default* pick such a type for the 
particular set of values you have. By default (to match traditions) gcc 
will always pick "int" (or, thanks to a gcc extension, a bigger type if 
the values require it), but if you pass it "-fshort-enums" it will pick a 
smaller type. 

And yes, it will actually pick "unsigned char", I think. Try it to be 
sure.

So to be portable, and to be safe, you really should make the error values 
part of the enum, ie you should add a

	OBJ_ERROR = -1,

if you want to make sure that the enum really can hold a negative number!

(In fact, on some embedded platforms, "-fshort-enums" is actually on by 
default - in order to keep data structures smaller)

		Linus

  reply	other threads:[~2007-02-27 16:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-26 19:55 various cleanups Nicolas Pitre
2007-02-26 19:55 ` [PATCH 1/6] sha1_file.c: cleanup hdr usage Nicolas Pitre
2007-02-26 19:55   ` [PATCH 2/6] sha1_file.c: cleanup "offset" usage Nicolas Pitre
2007-02-26 19:55     ` [PATCH 3/6] sha1_file.c: don't ignore an error condition in sha1_loose_object_info() Nicolas Pitre
2007-02-26 19:55       ` [PATCH 4/6] formalize typename(), and add its reverse type_from_string() Nicolas Pitre
2007-02-26 19:55         ` [PATCH 5/6] convert object type handling from a string to a number Nicolas Pitre
2007-02-26 19:56           ` [PATCH 6/6] get rid of lookup_object_type() Nicolas Pitre
2007-02-27 10:35           ` [PATCH 5/6] convert object type handling from a string to a number Junio C Hamano
2007-02-27 10:53             ` Junio C Hamano
2007-02-27 14:06               ` Nicolas Pitre
2007-02-27 13:58             ` Nicolas Pitre
2007-02-27 16:24               ` Linus Torvalds [this message]
2007-02-27 17:26                 ` Nicolas Pitre
2007-02-27 15:01             ` Shawn O. Pearce
2007-02-27 15:33               ` Nicolas Pitre
2007-02-27 16:07                 ` Shawn O. Pearce

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.64.0702270816350.12485@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=nico@cam.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).