[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 82bb990 2/2: Improve concinnity
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 82bb990 2/2: Improve concinnity |
Date: |
Sun, 11 Mar 2018 12:06:57 -0400 (EDT) |
branch: master
commit 82bb990abf6f0d5ca71d2d8e5a982cb544256cd8
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Improve concinnity
Write a comment explaining the condition for...
...the code that follows an #else directive
...the code that precedes an #endif directive
thus:
#if condition
#endif // condition
#if condition
#else // !condition
#endif // !condition
Prefer '#if defined FOO' to '#ifdef FOO' because it makes the condition
easy to copy to corresponding '#else' and '#endif' directives. Likewise
prefer '#if !defined FOO' to '#ifndef FOO'. This would be misleading:
#ifdef FOO
#endif // FOO
because the code above '#endif' depends not on whether FOO evaluates to
nonzero, but whether it is defined. Exception: write header guards for
'bar.hpp' thus:
#ifndef timer_hpp
#define timer_hpp
...
#endif // timer_hpp
to emphasize their distinctive purpose.
---
config.hpp | 12 ++++++------
config_bc551.hpp | 4 ++--
config_como_mingw.hpp | 4 ++--
config_ming323.hpp | 4 ++--
ihs_irc7702.cpp | 4 ++--
ihs_irc7702a.cpp | 4 ++--
input_sequence_entry.cpp | 8 ++++----
main_cgi.cpp | 8 ++++----
main_wx.cpp | 12 ++++++------
md5.cpp | 24 ++++++++++++------------
md5.hpp | 38 +++++++++++++++++++-------------------
msw_workarounds.cpp | 4 ++--
msw_workarounds.hpp | 4 ++--
name_value_pairs_test.cpp | 6 +++---
rate_table.cpp | 12 ++++++------
round_glibc.cpp | 20 ++++++++++----------
round_to_test.cpp | 2 +-
test_coding_rules.cpp | 24 ++++++++++++++++++++++++
test_coding_rules_test.sh | 14 ++++++++++++++
timer.cpp | 24 ++++++++++++------------
view_ex.cpp | 4 ++--
21 files changed, 137 insertions(+), 99 deletions(-)
diff --git a/config.hpp b/config.hpp
index 5986372..110742a 100644
--- a/config.hpp
+++ b/config.hpp
@@ -25,11 +25,11 @@
#ifndef config_hpp
#define config_hpp
-#ifdef __cplusplus
+#if defined __cplusplus
// Namespace alii.
namespace boost {namespace filesystem {} }
namespace fs = boost::filesystem;
-#endif // Not C++.
+#endif // defined __cplusplus
// The msw platform-identifying macro that its vendor encourages
// people to use contains the word "win". I don't consider a non-free
@@ -118,7 +118,7 @@ namespace fs = boost::filesystem;
#if defined __GNUC__
# define LMI_GCC_VERSION \
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
-#endif // __GNUC__
+#endif // defined __GNUC__
#if defined __COMO__
# define LMI_COMO_VERSION __COMO_VERSION__
@@ -138,12 +138,12 @@ namespace fs = boost::filesystem;
# if defined __MINGW32_VERSION || defined __MINGW_H
# define LMI_COMO_WITH_MINGW
# endif // defined __MINGW32_VERSION || defined __MINGW_H
-#endif // __COMO__
+#endif // defined __COMO__
#if defined __MINGW32__
// Get definition of __MINGW32_VERSION.
# include <_mingw.h>
-#endif // __MINGW32__
+#endif // defined __MINGW32__
// lmi used the mingw.org toolchain through gcc-3.4.5, and switched
// to MinGW-w64's gcc-4.9.2 circa 2016-01-01. To distinguish one from
@@ -158,7 +158,7 @@ namespace fs = boost::filesystem;
#if defined __MINGW32_VERSION || defined __MINGW64_VERSION_MAJOR
# define LMI_MINGW_VERSION \
(__MINGW32_MAJOR_VERSION * 100 + __MINGW32_MINOR_VERSION)
-#endif // __MINGW32_VERSION
+#endif // defined __MINGW32_VERSION || defined __MINGW64_VERSION_MAJOR
#if defined __BORLANDC__ && __BORLANDC__ < 0x0550
# error Obsolete compiler not supported.
diff --git a/config_bc551.hpp b/config_bc551.hpp
index df1c4f8..06a5ef5 100644
--- a/config_bc551.hpp
+++ b/config_bc551.hpp
@@ -24,9 +24,9 @@
#ifndef config_bc551_hpp
#define config_bc551_hpp
-#ifndef OK_TO_INCLUDE_CONFIG_BC551_HPP
+#if !defined OK_TO_INCLUDE_CONFIG_BC551_HPP
# error This file is not intended for separate inclusion.
-#endif // OK_TO_INCLUDE_CONFIG_BC551_HPP
+#endif // !defined OK_TO_INCLUDE_CONFIG_BC551_HPP
#if defined __BORLANDC__ && 0x0550 <= __BORLANDC__
# // Copacetic.
diff --git a/config_como_mingw.hpp b/config_como_mingw.hpp
index 282d6a0..16b8363 100644
--- a/config_como_mingw.hpp
+++ b/config_como_mingw.hpp
@@ -24,9 +24,9 @@
#ifndef config_como_mingw_hpp
#define config_como_mingw_hpp
-#ifndef OK_TO_INCLUDE_CONFIG_COMO_WITH_MINGW_HPP
+#if !defined OK_TO_INCLUDE_CONFIG_COMO_WITH_MINGW_HPP
# error This file is not intended for separate inclusion.
-#endif // OK_TO_INCLUDE_CONFIG_COMO_WITH_MINGW_HPP
+#endif // !defined OK_TO_INCLUDE_CONFIG_COMO_WITH_MINGW_HPP
#if defined LMI_COMO_WITH_MINGW
# // Copacetic.
diff --git a/config_ming323.hpp b/config_ming323.hpp
index 2d352c3..e57ceba 100644
--- a/config_ming323.hpp
+++ b/config_ming323.hpp
@@ -24,9 +24,9 @@
#ifndef config_ming323_hpp
#define config_ming323_hpp
-#ifndef OK_TO_INCLUDE_CONFIG_MING323_HPP
+#if !defined OK_TO_INCLUDE_CONFIG_MING323_HPP
# error This file is not intended for separate inclusion.
-#endif // OK_TO_INCLUDE_CONFIG_MING323_HPP
+#endif // !defined OK_TO_INCLUDE_CONFIG_MING323_HPP
#if 30203 <= LMI_GCC_VERSION
# // Copacetic.
diff --git a/ihs_irc7702.cpp b/ihs_irc7702.cpp
index 176c84a..e8ff861 100644
--- a/ihs_irc7702.cpp
+++ b/ihs_irc7702.cpp
@@ -1020,7 +1020,7 @@ double Irc7702::premiums_paid() const
}
// TAXATION !! TODO ?? This should be a separate, standalone unit test.
-#ifdef TESTING
+#if 0
#include "ihs_timer.hpp"
@@ -1075,5 +1075,5 @@ int main()
cout << timer.stop().elapsed_msec_str();
delete Irc7702_;
}
-#endif // TESTING
+#endif // 0
diff --git a/ihs_irc7702a.cpp b/ihs_irc7702a.cpp
index ecb66c1..8fd994a 100644
--- a/ihs_irc7702a.cpp
+++ b/ihs_irc7702a.cpp
@@ -931,7 +931,7 @@ double Irc7702A::UpdateBft7702A
}
// One school of thought treats any Bft increase following any unnec prem
// as a MatChg.
-#ifdef THIS_IS_NOT_DEFINED
+#if 0
// TODO ?? TAXATION !! Recognizing a MatChg wipes the slate clean: it is
as though no
// unnecessary premium had ever been paid. So 'UnnecPremEver' is
// a nonsensical notion.
@@ -939,7 +939,7 @@ double Irc7702A::UpdateBft7702A
{
is_material_change = true;
}
-#endif
+#endif // 0
if(is_material_change)
{
diff --git a/input_sequence_entry.cpp b/input_sequence_entry.cpp
index b449623..0ebb267 100644
--- a/input_sequence_entry.cpp
+++ b/input_sequence_entry.cpp
@@ -663,10 +663,10 @@ void InputSequenceEditor::insert_row(int new_row)
,wxDefaultSize
,wxBU_AUTODRAW | wxBU_EXACTFIT | wxBORDER_NONE
);
-#ifdef __WXGTK__
+#if defined __WXGTK__
wxBitmap removeBmp = wxArtProvider::GetBitmap("gtk-remove", wxART_BUTTON);
remove->SetBitmap(removeBmp);
-#endif
+#endif // defined __WXGTK__
remove->SetToolTip("Remove this row");
remove->Connect
@@ -685,10 +685,10 @@ void InputSequenceEditor::insert_row(int new_row)
,wxDefaultSize
,wxBU_AUTODRAW | wxBU_EXACTFIT | wxBORDER_NONE
);
-#ifdef __WXGTK__
+#if defined __WXGTK__
wxBitmap addBmp = wxArtProvider::GetBitmap("gtk-add", wxART_BUTTON);
add->SetBitmap(addBmp);
-#endif
+#endif // defined __WXGTK__
add->SetToolTip("Insert a new row after this one");
add->Connect
diff --git a/main_cgi.cpp b/main_cgi.cpp
index ea34bf1..2c06927 100644
--- a/main_cgi.cpp
+++ b/main_cgi.cpp
@@ -50,11 +50,11 @@
#include <cgicc/CgiEnvironment.h>
#include <cgicc/CgiUtils.h> // gLogFile
#include <cgicc/HTMLClasses.h>
-#ifdef USING_CURRENT_CGICC
+#if defined USING_CURRENT_CGICC
# include <cgicc/HTTPHTMLHeader.h> // cgicc-3.2.3
-#else // USING_CURRENT_CGICC not defined.
+#else // !defined USING_CURRENT_CGICC
# include <cgicc/HTTPHeaders.h>
-#endif // USING_CURRENT_CGICC not defined.
+#endif // !defined USING_CURRENT_CGICC
#include <cstring>
#include <exception>
@@ -69,7 +69,7 @@
#if defined HAVE_SYS_TIME_H && HAVE_SYS_TIME_H
# include <sys/time.h>
-#endif
+#endif // defined HAVE_SYS_TIME_H && HAVE_SYS_TIME_H
// To use logging, the variable gLogFile MUST be defined, and it _must_
// be an ofstream.
diff --git a/main_wx.cpp b/main_wx.cpp
index 6f9ad4a..3765811 100644
--- a/main_wx.cpp
+++ b/main_wx.cpp
@@ -53,16 +53,16 @@ LMI_FORCE_LINKING_EX_SITU(system_command_wx)
IMPLEMENT_APP_NO_MAIN(Skeleton)
IMPLEMENT_WX_THEME_SUPPORT
-#ifndef LMI_MSW
+#if !defined LMI_MSW
int main(int argc, char* argv[])
-#else // LMI_MSW defined.
+#else // defined LMI_MSW
int WINAPI WinMain
(HINSTANCE hInstance
,HINSTANCE hPrevInstance
,LPSTR lpCmdLine
,int nCmdShow
)
-#endif // LMI_MSW defined.
+#endif // defined LMI_MSW
{
// (Historical notes.) Using wx-2.5.1 and mpatrol-1.4.8, both
// dynamically linked to this application built with gcc-3.2.3,
@@ -89,11 +89,11 @@ int WINAPI WinMain
{
initialize_application();
initialize_filesystem();
-#ifndef LMI_MSW
+#if !defined LMI_MSW
result = wxEntry(argc, argv);
-#else // LMI_MSW defined.
+#else // defined LMI_MSW
result = wxEntry(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
-#endif // LMI_MSW defined.
+#endif // defined LMI_MSW
}
catch(...)
{
diff --git a/md5.cpp b/md5.cpp
index b82c588..b424d42 100644
--- a/md5.cpp
+++ b/md5.cpp
@@ -43,9 +43,9 @@
#include "pchfile.hpp"
// Suppress this because we wouldn't have glibc's 'config.h'.
-//#ifdef HAVE_CONFIG_H
+//#if defined HAVE_CONFIG_H
//# include <config.h>
-//#endif
+//#endif // defined HAVE_CONFIG_H
#include <sys/types.h>
@@ -59,11 +59,11 @@
#if 1
# include <cstdlib> // GWC replaced <stdlib.h> .
# include <cstring> // GWC replaced <string.h> .
-#else
-# ifndef HAVE_MEMCPY
+#else // 0
+# if !defined HAVE_MEMCPY
# define memcpy(d, s, n) bcopy ((s), (d), (n))
-# endif
-#endif
+# endif // !defined HAVE_MEMCPY
+#endif // 0
/* GWC: Suppress this unneeded, nonstandard header.
* #include "ansidecl.h"
@@ -71,20 +71,20 @@
/* GWC: File renamed md5.h --> md5.hpp . */
#include "md5.hpp"
-#ifdef _LIBC
+#if defined _LIBC
# include <endian.h>
# if __BYTE_ORDER == __BIG_ENDIAN
# define WORDS_BIGENDIAN 1
-# endif
-#endif
+# endif // __BYTE_ORDER == __BIG_ENDIAN
+#endif // defined _LIBC
/* intel x86 is litte-endian */
-#ifdef WORDS_BIGENDIAN
+#if defined WORDS_BIGENDIAN
# define SWAP(n) \
(((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
-#else
+#else // !defined WORDS_BIGENDIAN
# define SWAP(n) (n)
-#endif
+#endif // !defined WORDS_BIGENDIAN
/* This array contains the bytes used to pad the buffer to the next
* 64-byte boundary. (RFC 1321, 3.1: Step 1)
diff --git a/md5.hpp b/md5.hpp
index fb81257..66a5a32 100644
--- a/md5.hpp
+++ b/md5.hpp
@@ -51,14 +51,14 @@
#include <cstdio> // GWC added this required header.
/* GWC: Make this header usable with C++. */
-#ifdef __cplusplus
+#if defined __cplusplus
extern "C" {
-#endif /* __cplusplus */
+#endif // defined __cplusplus
/* GWC: Unconditionally assume we have the standard C headers.
* #if defined HAVE_LIMITS_H || _LIBC
* # include <limits.h>
- * #endif
+ * #endif // defined HAVE_LIMITS_H || _LIBC
*/
#include <limits.h>
@@ -70,10 +70,10 @@ extern "C" {
* is usually not possible.
*/
-#ifdef _LIBC
+#if defined _LIBC
# include <sys/types.h>
typedef u_int32_t md5_uint32;
-#else
+#else // !defined _LIBC
# define INT_MAX_32_BITS 2147483647
/* If UINT_MAX isn't defined, assume it's a 32-bit type.
@@ -82,27 +82,27 @@ typedef u_int32_t md5_uint32;
* (that certainly have <limits.h>) have 64+-bit integral types.
*/
-# ifndef INT_MAX
+# if !defined INT_MAX
# define INT_MAX INT_MAX_32_BITS
-# endif
+# endif // !defined INT_MAX
# if INT_MAX == INT_MAX_32_BITS
typedef unsigned int md5_uint32;
-# else
+# else // !INT_MAX == INT_MAX_32_BITS
# if SHRT_MAX == INT_MAX_32_BITS
typedef unsigned short int md5_uint32;
-# else
+# else // !SHRT_MAX == INT_MAX_32_BITS
# if LONG_MAX == INT_MAX_32_BITS
typedef unsigned long int md5_uint32;
-# else
+# else // !LONG_MAX == INT_MAX_32_BITS
/* The following line is intended to evoke an error.
* Using #error is not portable enough.
*/
"Cannot determine unsigned 32-bit data type."
-# endif
-# endif
-# endif
-#endif
+# endif // !LONG_MAX == INT_MAX_32_BITS
+# endif // !SHRT_MAX == INT_MAX_32_BITS
+# endif // !INT_MAX == INT_MAX_32_BITS
+#endif // !defined _LIBC
/* GWC: Here, __STDC__ is tested, but what should be done if that test
* fails? The gnu project assumes it may have a pre-1989 C compiler. I
@@ -119,11 +119,11 @@ typedef u_int32_t md5_uint32;
* avoid triggering lmi's tests for reserved identifiers.
*
* #undef MD5_P
- * #if defined (__STDC__) && __STDC__
+ * #if defined __STDC__ && __STDC__
* #define MD5_P(x) x
- * #else
+ * #else // !(defined __STDC__ && __STDC__)
* #define MD5_P(x) ()
- * #endif
+ * #endif // !(defined __STDC__ && __STDC__)
*/
#define LMI_P(x) x
@@ -197,9 +197,9 @@ extern int md5_stream LMI_P ((std::FILE *stream, void
*resblock));
* digest.
*/
extern void *md5_buffer LMI_P ((const char *buffer, std::size_t len, void
*resblock));
-#ifdef __cplusplus
+#if defined __cplusplus
} /* extern "C" */
-#endif /* __cplusplus */
+#endif // defined __cplusplus
/* GWC: Explicitly undefine prototype macro. */
#undef LMI_P
diff --git a/msw_workarounds.cpp b/msw_workarounds.cpp
index 0e7d64b..c4af9d9 100644
--- a/msw_workarounds.cpp
+++ b/msw_workarounds.cpp
@@ -23,7 +23,7 @@
#include "msw_workarounds.hpp"
-#ifdef LMI_MSW
+#if defined LMI_MSW
#include "alert.hpp"
#include "configurable_settings.hpp"
@@ -113,4 +113,4 @@ void MswDllPreloader::UnloadOneDll(std::string const&
dll_name)
}
}
-#endif // LMI_MSW defined.
+#endif // defined LMI_MSW
diff --git a/msw_workarounds.hpp b/msw_workarounds.hpp
index 5893ace..6709e44 100644
--- a/msw_workarounds.hpp
+++ b/msw_workarounds.hpp
@@ -24,7 +24,7 @@
#include "config.hpp"
-#ifdef LMI_MSW
+#if defined LMI_MSW
#include <deque>
#include <string>
@@ -64,7 +64,7 @@ class MswDllPreloader final
std::deque<std::string> SuccessfullyPreloadedDlls_;
};
-#endif // LMI_MSW defined.
+#endif // defined LMI_MSW
#endif // msw_workarounds_hpp
diff --git a/name_value_pairs_test.cpp b/name_value_pairs_test.cpp
index d4940e9..a5b913c 100644
--- a/name_value_pairs_test.cpp
+++ b/name_value_pairs_test.cpp
@@ -77,11 +77,11 @@ int test_main(int, char*[])
BOOST_TEST_EQUAL("" , n_v_pairs_0.string_value("c"));
BOOST_TEST_EQUAL("=" , n_v_pairs_0.string_value("d"));
BOOST_TEST_EQUAL("1=." , n_v_pairs_0.string_value("e"));
-#ifndef LMI_MSW
+#if !defined LMI_MSW
BOOST_TEST_EQUAL(" f \r" , n_v_pairs_0.string_value("f"));
-#else // LMI_MSW
+#else // defined LMI_MSW
BOOST_TEST_EQUAL(" f " , n_v_pairs_0.string_value("f"));
-#endif // LMI_MSW
+#endif // defined LMI_MSW
BOOST_TEST_EQUAL("a test", n_v_pairs_0.string_value("this"));
// Test numeric_value().
diff --git a/rate_table.cpp b/rate_table.cpp
index 49f85f1..4c32a51 100644
--- a/rate_table.cpp
+++ b/rate_table.cpp
@@ -89,7 +89,7 @@ std::uint8_t swap_bytes_if_big_endian(std::uint8_t val)
// We rely on makefile defining WORDS_BIGENDIAN on big endian architectures,
// conversions from little endian format are only needed there and are trivial
// on little endian machines.
-#ifdef WORDS_BIGENDIAN
+#if defined WORDS_BIGENDIAN
inline
std::uint16_t swap_bytes_if_big_endian(std::uint16_t val)
{
@@ -132,7 +132,7 @@ double swap_bytes_if_big_endian(double val)
// And vice versa.
return *reinterpret_cast<double*>(&ui64);
}
-#else // !WORDS_BIGENDIAN
+#else // !defined WORDS_BIGENDIAN
inline
std::uint16_t swap_bytes_if_big_endian(std::uint16_t val)
{
@@ -150,7 +150,7 @@ double swap_bytes_if_big_endian(double val)
{
return val;
}
-#endif // WORDS_BIGENDIAN/!WORDS_BIGENDIAN
+#endif // !defined WORDS_BIGENDIAN
template<typename T>
inline
@@ -433,7 +433,7 @@ void writer::write_values
write(e_field_select_period , select_period );
write(e_field_max_select_age , max_select_age );
-#ifdef WORDS_BIGENDIAN
+#if defined WORDS_BIGENDIAN
// Convert the values to their on disk representation.
std::vector<double> little_endian_values;
little_endian_values.reserve(values.size());
@@ -442,11 +442,11 @@ void writer::write_values
{
little_endian_values.push_back(swap_bytes_if_big_endian(v));
}
-#else // !WORDS_BIGENDIAN
+#else // !defined WORDS_BIGENDIAN
// No conversion necessary, don't create an extra vector needlessly, just
// alias the existing one.
std::vector<double> const& little_endian_values = values;
-#endif // WORDS_BIGENDIAN/!WORDS_BIGENDIAN
+#endif // !defined WORDS_BIGENDIAN
std::size_t const length = values.size()*sizeof(double);
diff --git a/round_glibc.cpp b/round_glibc.cpp
index dc7c324..3ef4ec4 100644
--- a/round_glibc.cpp
+++ b/round_glibc.cpp
@@ -105,7 +105,7 @@ typedef union
} parts;
uint64_t word;
} ieee_double_shape_type;
-#endif
+#endif // __FLOAT_WORD_ORDER == BIG_ENDIAN
#if __FLOAT_WORD_ORDER == LITTLE_ENDIAN
typedef union
@@ -118,7 +118,7 @@ typedef union
} parts;
uint64_t word;
} ieee_double_shape_type;
-#endif
+#endif // __FLOAT_WORD_ORDER == LITTLE_ENDIAN
/* Get two 32 bit ints from a double. */
@@ -131,7 +131,7 @@ do {
\
} while (0)
/* Set a double from two 32 bit ints. */
-#ifndef INSERT_WORDS
+#if !defined INSERT_WORDS
# define INSERT_WORDS(d,ix0,ix1) \
do { \
ieee_double_shape_type iw_u; \
@@ -139,7 +139,7 @@ do {
\
iw_u.parts.lsw = (ix1); \
(d) = iw_u.value; \
} while (0)
-#endif
+#endif // !defined INSERT_WORDS
/* A union which permits us to convert between a float and a 32 bit
int. */
@@ -151,24 +151,24 @@ typedef union
} ieee_float_shape_type;
/* Get a 32 bit int from a float. */
-#ifndef GET_FLOAT_WORD
+#if !defined GET_FLOAT_WORD
# define GET_FLOAT_WORD(i,d) \
do { \
ieee_float_shape_type gf_u; \
gf_u.value = (d); \
(i) = gf_u.word; \
} while (0)
-#endif
+#endif // !defined GET_FLOAT_WORD
/* Set a float from a 32 bit int. */
-#ifndef SET_FLOAT_WORD
+#if !defined SET_FLOAT_WORD
# define SET_FLOAT_WORD(d,i) \
do { \
ieee_float_shape_type sf_u; \
sf_u.word = (i); \
(d) = sf_u.value; \
} while (0)
-#endif
+#endif // !defined SET_FLOAT_WORD
//
https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=sysdeps/ieee754/ldbl-96/math_ldbl.h
@@ -187,7 +187,7 @@ typedef union
u_int32_t lsw;
} parts;
} ieee_long_double_shape_type;
-#endif
+#endif // __FLOAT_WORD_ORDER == BIG_ENDIAN
#if __FLOAT_WORD_ORDER == LITTLE_ENDIAN
typedef union
@@ -201,7 +201,7 @@ typedef union
unsigned int empty:16;
} parts;
} ieee_long_double_shape_type;
-#endif
+#endif // __FLOAT_WORD_ORDER == LITTLE_ENDIAN
/* Get three 32 bit ints from a double. */
diff --git a/round_to_test.cpp b/round_to_test.cpp
index f2d7b17..cb69355 100644
--- a/round_to_test.cpp
+++ b/round_to_test.cpp
@@ -239,7 +239,7 @@ bool test_one_case
- 1.0
;
}
-#ifdef LMI_COMO_WITH_MINGW
+#if defined LMI_COMO_WITH_MINGW
// COMPILER !! This looks like a como porting defect: with mingw
// as the underlying C compiler, a long double should occupy
// twelve bytes, ten significant and two for padding.
diff --git a/test_coding_rules.cpp b/test_coding_rules.cpp
index 5c1c11e..b8f30f7 100644
--- a/test_coding_rules.cpp
+++ b/test_coding_rules.cpp
@@ -563,6 +563,30 @@ void check_cxx(file const& f)
}
}
+ {
+ static boost::regex const r(R"(\n# *ifn*def[^\n]+\n)");
+ boost::sregex_iterator i(f.data().begin(), f.data().end(), r);
+ boost::sregex_iterator const omega;
+ for(; i != omega; ++i)
+ {
+ boost::smatch const& z(*i);
+ std::string s = z[0];
+ static boost::regex const include_guard(R"(# *ifndef
*\l[_\d\l]*_hpp\W)");
+ if(!boost::regex_search(s, include_guard))
+ {
+ ltrim(s, "\n");
+ rtrim(s, "\n");
+ std::ostringstream oss;
+ oss
+ << "should write '#if [!]defined' instead of '#if[n]def': '"
+ << s
+ << "'."
+ ;
+ complain(f, oss.str());
+ }
+ }
+ }
+
// Tests above: C or C++. Tests below: C++ only.
if(!f.is_of_phylum(e_cxx))
{
diff --git a/test_coding_rules_test.sh b/test_coding_rules_test.sh
index 3966c59..d7d2224 100755
--- a/test_coding_rules_test.sh
+++ b/test_coding_rules_test.sh
@@ -281,6 +281,18 @@ Missing compulsory include directive.
#endif // eraseme_hpp_006_hpp
EOF
+cat >eraseme_hpp_007.hpp <<EOF
+$boilerplate
+#ifndef eraseme_hpp_007_hpp
+#define eraseme_hpp_007_hpp
+#include "config.hpp"
+Should be 'defined XYZ'.
+#ifdef XYZ
+Should be '!defined __cplusplus'.
+#ifndef __cplusplus
+#endif // eraseme_hpp_007_hpp
+EOF
+
# Log files.
cat >eraseme_log_000.Log <<EOF
@@ -389,6 +401,8 @@ File 'eraseme_hpp_005.hpp' must include 'config.hpp' first.
File 'eraseme_hpp_006.hpp' must include 'config.hpp'.
File 'eraseme_hpp_006.hpp' lacks line '#include "config.hpp"'.
File 'eraseme_hpp_006.hpp' must include 'config.hpp' first.
+File 'eraseme_hpp_007.hpp' should write '#if [!]defined' instead of
'#if[n]def': '#ifdef XYZ'.
+File 'eraseme_hpp_007.hpp' should write '#if [!]defined' instead of
'#if[n]def': '#ifndef __cplusplus'.
File 'eraseme_log_001.Log' lacks expected 'MAINTENANCE' line.
File 'eraseme_log_001.Log' violates seventy-character limit:
0000000001111111111222222222233333333334444444444555555555566666666667
diff --git a/timer.cpp b/timer.cpp
index 38adeb5..33d40af 100644
--- a/timer.cpp
+++ b/timer.cpp
@@ -23,28 +23,28 @@
#include "timer.hpp"
-#ifdef LMI_MSW
+#if defined LMI_MSW
// TRICKY !! There being no standard way to ascertain whether
// <windows.h> has been included, we resort to this hack:
# if defined STDCALL || defined WM_COMMAND
# define LMI_MS_HEADER_INCLUDED
# endif // defined STDCALL || defined WM_COMMAND
// I'm not willing to bring in a zillion msw headers...
- //#ifdef LMI_MSW
+ //#if defined LMI_MSW
//# include <windows.h>
- //#endif // LMI_MSW
+ //#endif // defined LMI_MSW
// ...just to get a couple of prototypes, because that can materially
// increase compile times for small programs, and because it requires
// ms extensions and defines many macros.
-# ifndef LMI_MS_HEADER_INCLUDED
+# if !defined LMI_MS_HEADER_INCLUDED
// These declarations would be erroneous if the ms headers were
// included. It's necessary to guard against that explicitly,
// because those headers might be implicitly included by a pch
// mechanism.
extern "C" int __stdcall QueryPerformanceCounter(elapsed_t*);
extern "C" int __stdcall QueryPerformanceFrequency(elapsed_t*);
-# endif // LMI_MS_HEADER_INCLUDED
-#endif // LMI_MSW
+# endif // !defined LMI_MS_HEADER_INCLUDED
+#endif // defined LMI_MSW
/// Suspend execution for a given number of seconds.
@@ -150,15 +150,15 @@ elapsed_t Timer::calibrate()
#if defined LMI_POSIX
return 1000000;
#elif defined LMI_MSW
-# ifdef LMI_MS_HEADER_INCLUDED
+# if defined LMI_MS_HEADER_INCLUDED
LARGE_INTEGER z;
QueryPerformanceFrequency(&z);
return z.QuadPart;
-# else
+# else // !defined LMI_MS_HEADER_INCLUDED
elapsed_t z;
QueryPerformanceFrequency(&z);
return z;
-# endif // LMI_MS_HEADER_INCLUDED
+# endif // !defined LMI_MS_HEADER_INCLUDED
#else // Unknown platform.
return CLOCKS_PER_SEC;
#endif // Unknown platform.
@@ -188,15 +188,15 @@ elapsed_t Timer::inspect() const
gettimeofday(&x, nullptr);
return elapsed_t(1000000) * x.tv_sec + x.tv_usec;
#elif defined LMI_MSW
-# ifdef LMI_MS_HEADER_INCLUDED
+# if defined LMI_MS_HEADER_INCLUDED
LARGE_INTEGER z;
QueryPerformanceCounter(&z);
return z.QuadPart;
-# else
+# else // !defined LMI_MS_HEADER_INCLUDED
elapsed_t z;
QueryPerformanceCounter(&z);
return z;
-# endif // LMI_MS_HEADER_INCLUDED
+# endif // !defined LMI_MS_HEADER_INCLUDED
#else // Unknown platform.
return std::clock();
#endif // Unknown platform.
diff --git a/view_ex.cpp b/view_ex.cpp
index b46bbca..e701ac7 100644
--- a/view_ex.cpp
+++ b/view_ex.cpp
@@ -179,12 +179,12 @@ bool ViewEx::DoOnCreate(wxDocument* doc, long int)
child->SetFocus();
// WX !! This should be done inside the library.
-#ifdef __X__
+#if defined __X__
// The X Window Toolkit seems to require a forced resize.
int x, y;
GetFrame()->GetSize(&x, &y);
GetFrame()->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
-#endif
+#endif // defined __X__
GetFrame()->Show(true);
Activate(true);