gcc4.8 outperforming gcc5, gcc6, gcc7

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Dann Corbit
Posts: 12542
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: gcc4.8 outperforming gcc5, gcc6, gcc7

Post by Dann Corbit »

AndrewGrant wrote:That would be because of the patch I pushed yesterday... to allow indexing that array when in check (which means depth could be < 0).

I'm surprised I don't get these errors when I run my program through valgrind / gdb
You can check array bounds manually:

Code: Select all

		assert&#40;index >= 0&#41;;
		assert&#40;index < 64&#41;;
		piece&#91;index&#93; = aPiece;
		color&#91;index&#93; = aColor;
I have macros that I use for array bounds checks. I can't seem to find my macro set right now, but this is the general idea:

Code: Select all

#include <assert.h>
#include <stdlib.h>

#define single_dim_check&#40; a, x ) ( &#40;assert&#40; &#40;x >= 0 ) && &#40;sizeof a / sizeof a&#91;0&#93; > x ) ) )

int main&#40;void&#41;
&#123;
    int a&#91;5&#93;;
    size_t index = 6;
    single_dim_check&#40;a,index&#41;;
    
    return 0;
&#125;
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.