|
From: | Paul Eggert |
Subject: | Re: z/OS enum size pitfall |
Date: | Tue, 22 Aug 2017 14:43:23 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 |
On 08/22/2017 01:13 PM, Daniel Richard G. wrote:
I have been in contact with IBM about this, originally reporting the issue as a compiler bug. However, they responded that the compiler behavior is conformant to the C standard and that they are less concerned with matching the behavior of other systems than keeping things as-is for the benefit of existing customer application code.
There seems to be some miscommunication here. The enum type might be either signed or unsigned, and I expect this is what IBM is talking about. However, the enum constants that are declared all must be of type 'int'. This requirement has been in the standard for ages. For example, given:
enum { a, b, c } v = a;The expression "a < -1" must return 0, because a is zero and is of type int. However, the expression "v < -1" might return 0 (if v is signed) and it might return 1 (if v is unsigned). This is the case even though v is zero, just as a is. Since the code in question is using the enum constants, not the enum type, it must treat the values as signed integers in any conforming compiler.
[Prev in Thread] | Current Thread | [Next in Thread] |