Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Unnamed structs in C--bad?

Author: David Blackman

Date: 21:26:18 12/02/99

Go up one level in this thread


On December 02, 1999 at 16:21:48, Tom Kerrigan wrote:

>I'm currently using the following to define a move:
>
>typedef union {
>  int i;
>  struct {
>    char from;
>    char to;
>    char promote;
>    char flags;
>  };
>} move_t;

>-Tom

How will you access the fields? I think you at least need a name between
} and ; . That would then be legal C++, but not legal C as far as i remember.

The other thing is how much does this buy you? My guess is not much, but i
suppose there might be a compiler that generates getter code this way.

If this really matters a lot, you could declare a C++ class whose only data
member is and int, and declare inline methods with shift and mask to get at the
char fields.



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.