Professional Web Applications Themes

A bug in SunOne C compiler? - UNIX Programming

Hi, I am running the latest SunOne C compiler with the latest patches installed (cc -V show "cc: Sun C 5.5 Patch 112761-04 2003/10/03") and it can't compile the following (self-contained) code segment: ------ file cplx.c -------- #include <math.h> typedef struct { double real; double imag; } cplx_t; const static cplx_t C0 = {0.0, 0.0}; int abend = 0; #define INF 0x7ff00000 #ifdef __i386 #define OFFSET 1 #else #define OFFSET 0 #endif double fpof(double a) /* floating point routine output filter */ { union { unsigned i[2]; double d; } fp; fp.d = a; if ( (fp.i[OFFSET] & INF) == ...

  1. #1

    Default A bug in SunOne C compiler?

    Hi,

    I am running the latest SunOne C compiler with the latest patches installed
    (cc -V show "cc: Sun C 5.5 Patch 112761-04 2003/10/03")
    and it can't compile the following (self-contained) code segment:

    ------ file cplx.c --------
    #include <math.h>

    typedef struct {
    double real;
    double imag;
    } cplx_t;

    const static cplx_t C0 = {0.0, 0.0};

    int abend = 0;

    #define INF 0x7ff00000

    #ifdef __i386
    #define OFFSET 1
    #else
    #define OFFSET 0
    #endif


    double fpof(double a) /* floating point routine output filter */
    {
    union {
    unsigned i[2];
    double d;
    } fp;

    fp.d = a;
    if ( (fp.i[OFFSET] & INF) == INF ) abend = 1;
    return a;
    }

    cplx_t zmul(cplx_t z, cplx_t u)
    {
    cplx_t w;

    w.real = fpof(z.real*u.real - z.imag*u.imag);
    w.imag = fpof(z.real*u.imag + z.imag*u.real);

    return (abend?C0:w);
    }

    cplx_t zexp( cplx_t z )
    {
    cplx_t w;
    double r = fpof(exp(z.real));

    if (abend)
    return C0;

    w.real = fpof(r*cos(z.imag));
    w.imag = fpof(r*sin(z.imag));
    if (abend)
    return C0;
    else
    return w;
    }
    --------- end of cplx.c file --------------

    Here is the error message I am getting:

    % cc -c cplx.c
    "cplx.c", line 40: operands have incompatible types:
    const struct {double real, double imag} ":" struct {double real, double imag}
    cc: acomp failed for cplx.c
    %

    Note that the error is for '?' operator, whereas the equivalent if statement
    at the end of zexp() function works fine.

    Also, gcc works just fine here. This is on both Intel and SPARC platforms
    (one running s10_b42, the other running Solaris 8).

    Is this a (known) compiler bug? Is there any patch for it?

    Thanks and bye, Dragan

    --
    Dragan Cvetkovic,

    To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer

    !!! Sender/From address is bogus. Use reply-to one !!!
    Dragan Guest

  2. #2

    Default Re: A bug in SunOne C compiler?

    Dragan Cvetkovic <net> writes:
     

    [snip]
     

    It's the "const" that's causing the trouble. Many compilers require
    both sides of a ?: operator to have *exactly* the same type.
    Apparently the Sun compiler gets upset by one of the values being
    "const".
     

    GCC is usually rather forgiving when it comes to type compatibility.
     

    I wouldn't exactly call it a bug. Try casting the non-const value to
    (const cplx_t).

    --
    Måns Rullgård
    se
    Måns Guest

  3. Moderated Post

    Default Re: A bug in SunOne C compiler?

    Removed by Administrator
    Dragan Guest
    Moderated Post

  4. Moderated Post

    Default Re: A bug in SunOne C compiler?

    Removed by Administrator
    Måns Guest
    Moderated Post

  5. Moderated Post

    Default Re: A bug in SunOne C compiler?

    Removed by Administrator
    Dragan Guest
    Moderated Post

  6. Moderated Post

    Default Re: A bug in SunOne C compiler?

    Removed by Administrator
    Paul Guest
    Moderated Post

  7. #7

    Default Re: A bug in SunOne C compiler?

    In article <net>,
    Dragan Cvetkovic <net> wrote: 
    ....
     

    It is hard to tell what should be correct:

    In case of the if then else construct, it is obvious that the const
    var is copied into the return value so there is no problem with loosing
    the const qualifier.

    In case of the '?' expression, it is acting as a single value so there
    is not a unique type of the expression. As Sun's compiler does not accept

    return (abend?C0:(const cplx_t)w);

    which would result in a unique type before the assinement takes place,
    I tend to call it a Sun compiler bug.

    --
    EMail:isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin
    tu-berlin.de (uni) If you don't have iso-8859-1
    fraunhofer.de (work) chars I am J"org Schilling
    URL: http://www.fokus.fraunhofer.de/usr/schilling ftp://ftp.berlios.de/pub/schily
    Joerg Guest

Similar Threads

  1. ColdFusion MX7 with Sunone Webserver 7.0
    By Vkoppolu in forum Coldfusion Server Administration
    Replies: 2
    Last Post: March 14th, 06:30 PM
  2. Coldfusion Enterprise and SunOne
    By whgill in forum Coldfusion Server Administration
    Replies: 1
    Last Post: September 12th, 08:09 PM
  3. Solairs 9 SUNONE + Win2K3 AD
    By Rodrick Brown in forum Linux / Unix Administration
    Replies: 3
    Last Post: October 15th, 03:53 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139