You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: user-guide/modules/ROOT/pages/faq.adoc
+165Lines changed: 165 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,7 @@ This section contains answers to the common questions that new developers to Boo
25
25
* <<Metaprogramming>>
26
26
* <<Modular Boost>>
27
27
* <<Other Languages>>
28
+
* <<Production and Debug Builds>>
28
29
* <<Releases>>
29
30
* <<Safe C++>>
30
31
* <<Smart Pointers>>
@@ -1020,6 +1021,170 @@ Future technological shifts, such as advances in quantum computing or entirely n
1020
1021
+
1021
1022
Python is often the top recommendation due to its versatility, simplicity, and wide application in growing fields like artificial intelligence (AI), machine learning (ML), rapid prototyping, and data science. And boost:python[] is there to help you integrate with the Boost libraries. Rust is another strong contender, especially if you are interested in systems programming and are looking for reliability and security. If you see the future as more cloud computing, then Go makes a strong case for itself. And let's not forget that so much computing is now web based, so JavaScript deserves a mention here too. All of these languages offer valuable resources that complement pass:[C++] and prepare you for an uncertain future.
1022
1023
1024
+
== Production and Debug Builds
1025
+
1026
+
. *What is the value of using `BOOST_ASSERT` or `BOOST_STATIC_ASSERT` over the Standard Library assert macros?*
1027
+
+
1028
+
There are a few advantages of using the Boost asserts, available in `<boost/assert.hpp>`, including that `BOOST_ASSERT` is fully customizable using `BOOST_ENABLE_ASSERT_HANDLER`, which can be used to log extra data or stack traces, and there is better integration with boost:test[]. `BOOST_STATIC_ASSERT` is best utilized when using older pass:[C++] standards (pre-pass:[C++17]), or you are using deeply templated code. You might also prefer the Boost macros if you are engaging the features of other Boost libraries and are looking for consistent tooling. For a fuller discussion, refer to xref:boost-macros.adoc[].
1029
+
1030
+
. *For maximum performance, is it good practice to remove, or comment out, the `BOOST_ASSERT`s for the final production code, or do they simply not get compiled into anything so there is no performance cost for leaving them as is?*
1031
+
+
1032
+
By default, `BOOST_ASSERT` macros are completely removed from the compiled binary when `NDEBUG` is defined, just like the standard assert macro. If `NDEBUG` is not defined a `BOOST_ASSERT(x)` will expand, usually to an `assertion_failed()` if the assert condition fails. If NDEBUG is defined it expands to `((void)0)` so nothing is generated. Boost does provide the `BOOST_DISABLE_ASSERTS` macro, which has the same effect on Boost asserts as `NDEBUG` - but will leave other asserts alone.
1033
+
1034
+
. *What is usually considered to be best practices in handling assertions that fire with a production build?*
1035
+
+
1036
+
Instead of throwing an exception when an assert fails, it is often the best practice to log the failure. For example, here is a custom assert handler using the features of boost:log[] to record the event:
- [ ] Review conditional macros like `BOOST_NO_EXCEPTIONS`, `BOOST_NO_RTTI`, etc.
1129
+
- *Assertions and Diagnostics*
1130
+
- [ ] Use `BOOST_ASSERT` for critical development-time checks.
1131
+
- [ ] Consider diagnostic logging using `BOOST_LOG_TRIVIAL`.
1132
+
- [ ] Ensure failing assertions are tested and logged in Debug builds.
1133
+
- *Debugging and Tooling*
1134
+
- [ ] Run AddressSanitizer, Valgrind, or Visual Leak Detector in Debug builds. Refer to xref:contributor-guide:ROOT:testing/sanitizers.adoc[Contributor Guide: Sanitizers].
- [ ] Validate boost:thread[], boost:asio[], and boost:fiber[] components using thread sanitizers.
1137
+
- *Performance Awareness*
1138
+
- [ ] Avoid benchmarking with Debug builds — optimization is disabled.
1139
+
- [ ] Use Release builds to test compile times for boost:mp11[], boost:spirit[], and any heavy use of templates.
1140
+
- [ ] Validate any `BOOST_FORCEINLINE` or `BOOST_NOINLINE` effects in both builds.
1141
+
- *Unit Testing*
1142
+
- [ ] Run the full suite of unit tests in both Debug and Release.
1143
+
- [ ] Ensure no logic is only covered by Debug-only paths or assertions.
1144
+
- [ ] Use boost:test[] to validate results across optimization levels.
1145
+
1146
+
. *Typically, how should I set up a CMake file to handle Debug and Release builds?*
1147
+
+
1148
+
Here's an example of how to set up your `CMakeLists.txt` to handle `BOOST_ASSERT` correctly by toggling behavior based on the build type (Debug or Release). The example includes linking with some sample libraries (boost:log[], boost:system[] and boost:thread[]):
0 commit comments