Author: Russell Reagan
Date: 11:46:11 03/11/03
I got some warnings yesterday from my compiler about mixing data types. One
warning said something like, "converting bool to int, performance warning", or
something similar. What is good practice regarding the use of different sized
variables together? One example from my program is that I store the move as a
struct with several byte sized fields. My thinking is that since I will need to
save the move everytime I make a move, I can copy those 4 bytes once, instead of
having to do 4 copies of 32-bit values.
typedef struct {
unsigned char from;
unsigned char to;
unsigned char type;
unsigned char whatever;
} Move;
Instead of:
typedef struct {
unsigned int from;
unsigned int to;
unsigned int type;
unsigned int whatever;
} Move;
I got another warning when using an unsigned char as my board index, and using a
signed char as the offset from that index (it might have been a different
situation, but it was something similar, when I was mixing unsigned with
signed).
I got various warnings about mixing char with int, unsigned with signed, and so
on. They were not all performance warnings, but I would like to know if it is
better to use the smaller structure and save time copying it, or if it is better
to use the larger structure and work with "faster" variables. It seems like you
could keep more stuff in the cache if you used smaller sized variables when
suitable. I'd also like to know if there are ever performance issues when mixing
variables of different types (mixing char w/ short w/ long, unsigned w/ signed,
etc.).
Thanks,
Russell
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.