Why are enums with negative values causing problems in Objective-C/C? -


for various implementation reasons, i've defined following enum:

typedef enum hbsnakemovementdirection {     hbsnakemovementdirectionup = 1,     hbsnakemovementdirectiondown = -1,     hbsnakemovementdirectionright = 2,     hbsnakemovementdirectionleft = -2 } hbsnakemovementdirection; 

however, if try use hbsnakemovementdirectionright, following warning:

implicit conversion changes signedness: 'int' 'hbsnakemovementdirection'

it has no problem of other enum values. what's problem here? thought might have mixing negative , positive enum values, can't find out definitive this.

(i able come positive enum values allow me work around issue, still stumped me, thought i'd ask it.)

i should state that, projects, enable every warning—hence, -wconversion's complaints—and treat them errors. (i strict possible @ compile time.) i'm using llvm 1.6.

update 1: literally use of hbsnakemovementdirectionright results in preceding warning:

hbsnakemovementdirection movementdirectionright = hbsnakemovementdirectionright; 

i have cast hbsnakemovementdirectionright hbsnakemovementdirection silence warning.

update 2: requested, here entire build command that's being issued on machine:

http://pastie.org/1580957

update 3: here exact project i'm working on hosted on github:

https://github.com/lucastizma/hebi

specifically, following tree:

https://github.com/lucastizma/hebi/tree/89262e2e53881584daf029e3dd5f1e99dfbd6f96

as darren said, compiler bug, , dave said doesn’t happen clang 2.0.

i’ve found following type definition makes op code compile clang 1.6:

typedef enum hbsnakemovementdirection  {     hbsnakemovementdirectionup = 1,     // default movement direction upon initialization via -init     hbsnakemovementdirectiondown = -1,     hbsnakemovementdirectionleft = -2,     hbsnakemovementdirectionright = 2,     nbsnakemovementdirectionnone = -3 } hbsnakemovementdirection; 

(note additional nbsnakemovementdirectionnone)

this related llvm bug 1884, has been fixed.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -