gnugo-devel
[Top][All Lists]
Advanced

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

Re: [gnugo-devel] union in gnugo3.5.6


From: Dave Denholm
Subject: Re: [gnugo-devel] union in gnugo3.5.6
Date: Tue, 04 May 2004 15:56:01 +0100
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.2 (usg-unix-v)

address@hidden (Wolfgang Manner) writes:

> Friends !
> At work i have gcc 3.2 and gnugo-3.5.6 compiles perfectly.
> However at home i have gcc 2.95 and that doesnt like the
> anonymous union in patterns/patterns.h
> so i propose to name the union.
> That way you can also get rid of the
> ifdef __GNUC__
>

Have you tested this on a non-gcc compiler ?

The ability to initialise a particular field of a union (anonymous or otherwise)
is (used to be) a gcc extension. Which is why it was done this weird way
in the first place.

ie  given

 union u {
   int x;
   float f;
 };

gcc allows something along the lines of

union u fred = { x = 3 };
union u joe = { f = 0.5 };

or something along those lines, but that's non-standard. Standard c89 only
allows the first field of the union to be initialisd. (k&r 2nd edition p 219)


However, things may have moved on.


>    fprintf(outfile, "static struct pattern_attribute attributes[] = {\n");
> -  fprintf(outfile, "#ifdef __GNUC__\n");
>  
>    for (k = 0; k < num_attributes; k++) {
>      fprintf(outfile, "  {%s,", attribute_name[attributes[k].type]);
>      if (attributes[k].type >= FIRST_OFFSET_ATTRIBUTE)
> -      fprintf(outfile, "{.offset=%d}}", attributes[k].offset);
> +      fprintf(outfile, "{.offset=%d}}", attributes[k].A.offset);
>      else
> -      fprintf(outfile, "{.value=%f}}", attributes[k].value);
> +      fprintf(outfile, "{.value=%f}}", attributes[k].A.value);
>  
>      if (k != num_attributes - 1)
>        fprintf(outfile, ",\n");
>    }
>  
> -  fprintf(outfile, "\n#else\n");
> +  fprintf(outfile,"\n};\n\n");
>  
> -  for (k = 0; k < num_attributes; k++) {
> -    fprintf(outfile, "  {%s,", attribute_name[attributes[k].type]);
> -    if (attributes[k].type >= FIRST_OFFSET_ATTRIBUTE)
> -      fprintf(outfile, "0.0,%d}", attributes[k].offset);
> -    else
> -      fprintf(outfile, "%f,0}", attributes[k].value);
> -
> -    if (k != num_attributes - 1)
> -      fprintf(outfile, ",\n");
> -  }
> -
> -  fprintf(outfile,"\n#endif\n};\n\n");
>  }
>  
>  
>  
>  /*
>   * Each pattern as a whole is compiled to an instance of this structure.
>
>


This is the bit that concerns me - how does the initialiser for the patter
look in a non-gcc compiler ?


dd
-- 
Dave Denholm              <address@hidden>       http://www.esmertec.com




reply via email to

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