This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: isinf





Eric Botcazou <ebotcazou@libertysurf.fr> wrote on 14/07/2005 10:05:50:
[...]
> union U {
>   int i;
>   double d;
> };
>
> volatile int a;
>
> int
> main (int argc, char *argv[])
> {
>   union U u;
>   u.i = argc;
>   a = isinf (u.d);
>   return 0;
> }
>

Doesn't the code display undefined behavior when sizeof(u.i)<sizeof(u.d) ?
Not all of u.d will be initialized by u.i = argc, accessing the
uninitialized bits of u.d may trigger undefined behavior.

Maybe there is a simpler way? For example:

volatile int a;
volatile double b;
int main ()
{
   a = isinf (b);
   return 0;
}

This way the compiler must not assume anything about 'b',
making it impossible to optimizes the call to isinf.

  Michael


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]