bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

z/OS enum size pitfall


From: Daniel Richard G.
Subject: z/OS enum size pitfall
Date: Tue, 22 Aug 2017 16:13:54 -0400

Hello list,

I'm writing in to report a bizarre issue with the IBM z/OS XLC compiler
that is currently causing one gnulib test to fail (test-timespec), and
may present an issue for application code simply because no other
compiler does things this way. My hope is to have gnulib integrate a
workaround so that this won't bite anyone else.

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.

The problem has to do with the implicit integer type that is used for
enum symbols. Here is a sample program that illustrates the issue:

--------8<--------
#include <stdio.h>

enum { BILLION = 1000000000 };

static const unsigned int BILLION2 = 1000000000;

int main(void) {
    int x = -999999999;
    printf("BILLION = %d\n", (int)BILLION);
    printf("x = %d\n", x);
    printf("x / BILLION = %d\n", (int)(x / BILLION));
    return 0;
}
-------->8--------

On GNU/Linux and AIX, with a minimal compiler invocation, this
program prints

    BILLION = 1000000000
    x = -999999999
    x / BILLION = 0

However, on z/OS, it prints

    BILLION = 1000000000
    x = -999999999
    x / BILLION = 3

What happens is that BILLION is implicitly typed as an unsigned int,
rather than an int. If you edit the code above to use BILLION2 instead
of BILLION, you'll see the same result on GNU/Linux.

test-timespec fails not because of the time function being tested, but
because of how TIMESPEC_RESOLUTION is defined in timespec.h.

IBM, in their response, suggested specifying the flag -qenumsize=4 .
With this flag, the output on z/OS matches that of other systems,
test-timespec passes, and the rest of the gnulib test suite is
unaffected. I think it may be worth considering having gnulib add this
flag by default on z/OS, to get the expected behavior.


--Daniel


-- 
Daniel Richard G. || address@hidden
My ASCII-art .sig got a bad case of Times New Roman.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]