From: lucasart Date: Sat, 1 Nov 2014 20:35:10 +0000 (+0000) Subject: Consistent use of anonymous namespace X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=8a7876d48d4360d14d918c1ff444b5d6eb0382de Consistent use of anonymous namespace Objects that are only accessible at file-scope should be put in the anonymous namespace. This is what the C++ standard recommends, rather than using static, which is really C-style and results in static linkage. Stockfish already does this throughout the code. So let's weed out the few exceptions, because... they have no reason to be exceptional. No functional change. Resolves #84 --- diff --git a/src/benchmark.cpp b/src/benchmark.cpp index c861c8f3..1d97c95b 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -32,7 +32,9 @@ using namespace std; -static const char* Defaults[] = { +namespace { + +const char* Defaults[] = { "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10", "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11", @@ -65,6 +67,7 @@ static const char* Defaults[] = { "8/3p3B/5p2/5P2/p7/PP5b/k7/6K1 w - - 0 1" }; +} // namespace /// benchmark() runs a simple benchmark by letting Stockfish analyze a set /// of positions for a given limit each. There are five parameters: the diff --git a/src/misc.cpp b/src/misc.cpp index 4d062822..0052f21e 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -27,58 +27,14 @@ using namespace std; +namespace { + /// Version number. If Version is left empty, then compile date in the format /// DD-MM-YY and show in engine_info. -static const string Version = ""; - - -/// engine_info() returns the full name of the current Stockfish version. This -/// will be either "Stockfish DD-MM-YY" (where DD-MM-YY is the date when -/// the program was compiled) or "Stockfish ", depending on whether -/// Version is empty. - -const string engine_info(bool to_uci) { - - const string months("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"); - string month, day, year; - stringstream ss, date(__DATE__); // From compiler, format is "Sep 21 2008" - - ss << "Stockfish " << Version << setfill('0'); - - if (Version.empty()) - { - date >> month >> day >> year; - ss << setw(2) << day << setw(2) << (1 + months.find(month) / 4) << year.substr(2); - } - - ss << (Is64Bit ? " 64" : "") - << (HasPext ? " BMI2" : (HasPopCnt ? " SSE4.2" : "")) - << (to_uci ? "\nid author ": " by ") - << "Tord Romstad, Marco Costalba and Joona Kiiski"; - - return ss.str(); -} - - -/// Debug functions used mainly to collect run-time statistics - -static int64_t hits[2], means[2]; - -void dbg_hit_on(bool b) { ++hits[0]; if (b) ++hits[1]; } -void dbg_hit_on_c(bool c, bool b) { if (c) dbg_hit_on(b); } -void dbg_mean_of(int v) { ++means[0]; means[1] += v; } - -void dbg_print() { - - if (hits[0]) - cerr << "Total " << hits[0] << " Hits " << hits[1] - << " hit rate (%) " << 100 * hits[1] / hits[0] << endl; - - if (means[0]) - cerr << "Total " << means[0] << " Mean " - << (double)means[1] / means[0] << endl; -} +const string Version = ""; +/// Debug counters +int64_t hits[2], means[2]; /// Our fancy logging facility. The trick here is to replace cin.rdbuf() and /// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We @@ -137,6 +93,53 @@ public: } }; +} // namespace + +/// engine_info() returns the full name of the current Stockfish version. This +/// will be either "Stockfish DD-MM-YY" (where DD-MM-YY is the date when +/// the program was compiled) or "Stockfish ", depending on whether +/// Version is empty. + +const string engine_info(bool to_uci) { + + const string months("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"); + string month, day, year; + stringstream ss, date(__DATE__); // From compiler, format is "Sep 21 2008" + + ss << "Stockfish " << Version << setfill('0'); + + if (Version.empty()) + { + date >> month >> day >> year; + ss << setw(2) << day << setw(2) << (1 + months.find(month) / 4) << year.substr(2); + } + + ss << (Is64Bit ? " 64" : "") + << (HasPext ? " BMI2" : (HasPopCnt ? " SSE4.2" : "")) + << (to_uci ? "\nid author ": " by ") + << "Tord Romstad, Marco Costalba and Joona Kiiski"; + + return ss.str(); +} + + +/// Debug functions used mainly to collect run-time statistics + +void dbg_hit_on(bool b) { ++hits[0]; if (b) ++hits[1]; } +void dbg_hit_on_c(bool c, bool b) { if (c) dbg_hit_on(b); } +void dbg_mean_of(int v) { ++means[0]; means[1] += v; } + +void dbg_print() { + + if (hits[0]) + cerr << "Total " << hits[0] << " Hits " << hits[1] + << " hit rate (%) " << 100 * hits[1] / hits[0] << endl; + + if (means[0]) + cerr << "Total " << means[0] << " Mean " + << (double)means[1] / means[0] << endl; +} + /// Used to serialize access to std::cout to avoid multiple threads writing at /// the same time. diff --git a/src/movepick.cpp b/src/movepick.cpp index 95172b94..84f26dbf 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -61,7 +61,7 @@ namespace { std::swap(*begin, *std::max_element(begin, end)); return begin; } -} +} // namespace /// Constructors of the MovePicker class. As arguments we pass information diff --git a/src/position.cpp b/src/position.cpp index 4f72d658..918d50e5 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -34,16 +34,12 @@ using std::string; -static const string PieceToChar(" PNBRQK pnbrqk"); - CACHE_LINE_ALIGNMENT Value PieceValue[PHASE_NB][PIECE_NB] = { { VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg }, { VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg } }; -static Score psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB]; - namespace Zobrist { Key psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB]; @@ -57,6 +53,9 @@ Key Position::exclusion_key() const { return st->key ^ Zobrist::exclusion;} namespace { +const string PieceToChar(" PNBRQK pnbrqk"); +Score psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB]; + // min_attacker() is a helper function used by see() to locate the least // valuable attacker for the side to move, remove the attacker we just found // from the bitboards and scan for new X-ray attacks behind it.