1 Reply Latest reply on Apr 25, 2018 4:59 PM by David Pagan-Oracle

    Incorrect result type from ternary operator


      According to the C specification (3.3.15 in C89, 6.5.15¶6 in both C99 and C11), "if one operand is a null pointer constant, the result has the type of the other operand". This doesn't appear to be the case for suncc. Here is a test using _Generic which works in other C11 compilers but not suncc:


      #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L)

      #  error Requires C11



      #include <assert.h>

      #include <stddef.h>

      #include <stdint.h>


      #define IS_CONSTEXPR(expr) _Generic((1 ? (void*) (intptr_t) ((expr) * 0) : (int*) 0), int*: 1, void*: 0)

      #define REQUIRE_CONSTEXPR(expr) (IS_CONSTEXPR(expr) ? (expr) : -1)


      int main(int argc, char** argv) {

        int foo[REQUIRE_CONSTEXPR(42)];

        assert(IS_CONSTEXPR(42) == 1);

        assert(IS_CONSTEXPR(argc) == 0);



      There is some more information on how and why this works in C11 at https://stackoverflow.com/questions/49480442/detecting-integer-constant-expressions-in-macros/49481840