digideskio / protobuf-c

Automatically exported from code.google.com/p/protobuf-c
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Dangerous assumption that enums are 32 bits #80

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
All the code that deals with enum fields treats them as Uint32, which is not 
necessarily true. I'm using protobuf-c on a 16-bit embedded target.

The best way to solve it would be something like
(1) define
  typedef int enum_t;
(This is generally the case, but more importantly, a system-wide change can be 
affected by changing this on line of code)

(2) replace all Uint32 references with regards to enums with enum_t instead.

Original issue reported on code.google.com by martin.s...@gmail.com on 10 Apr 2012 at 5:33

GoogleCodeExporter commented 8 years ago
I would expect a value passed as an argument to a function, or assigned to a 
structure field that is 32-bits, the compiler should be automatically upgrading 
the value to 32-bits. Are you seeing something contrary to this?

Or... are you saying that this is 16-bits on your system and not being 
interpreted correctly? (Here's the generated output header from one of the 
protobuf-c test files):

typedef enum _Foo__Person__PhoneType {
  FOO__PERSON__PHONE_TYPE__MOBILE = 0,
  FOO__PERSON__PHONE_TYPE__HOME = 1,
  FOO__PERSON__PHONE_TYPE__WORK = 2
} Foo__Person__PhoneType;

Original comment by sodab...@gmail.com on 1 Aug 2012 at 9:44