Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: (Bit offtopic) ANSI C, bitfields and anonymous unions

Author: Gareth McCaughan

Date: 16:45:14 06/26/00

Go up one level in this thread


On June 26, 2000 at 17:10:40, Gian-Carlo Pascutto wrote:

> I'm wondering whether the following code is legal ANSI C:
>
> typedef struct {
>   int from;
>   int target;
>   int captured;
>   int cap_num;
>   union
>   {
>       unsigned int castled:4, was_promoted:1, ep:1, promoted:4;
>       unsigned int xx;
>   };
> } move_s;

No. ANSI C doesn't do that sort of anonymous union. (C++ does.)

> I suppose one way to fix this would be to name the union, but that
> would require all code which uses the castled, was_promoted, ...
> fields to be rewritten...not a nice prospect.

You should do that, even so. Can't you write a perl script or something
similar to do most of the work? (If you have other structs or unions
with members called castled, was_promoted, ep, promoted, or xx,
then it will be a little harder.)

--
g



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.