Closed LeStarch closed 10 months ago
BUILD_UT is not guaranteed to be set and thus #if BUILD_UT should be replaced with #if (defined(BUILD_UT) && BUILD_UT)
If BUILD_UT is not defined, then #if BUILD_UT
is compiled as #if 0
, isn't it? So what's the problem?
Also: the use of #if X
is pervasive in the generated code. If there is something wrong with this pattern then we should reconsider it everywhere, not just for BUILD_UT.
Doing this is impractical when they wish the release to be without FW_SERIALIZABLE_TO_STRING as there is only one configuration file.
Wouldn't #define FW_SERIALIZABLE_TO_STRING BUILD_UT
work?
More generally, I have always wondered why we say #if X
instead of #ifdef X
for on/off flags. I think #ifdef X
is more common. So maybe we should consistently use #ifdef X
for binary flags and #if X
only where X can have more than two values. Again, this is a pervasive issue in F Prime generated code, not just a BUILD_UT issue.
If we did it this way, then we could write
#ifdef BUILD_UT
#define FW_SERIALIZABLE_TO_STRING
#endif
to turn on serializable strings in UTs only.
#if BUILD_UT
when BUILD_UT
is not defined results in an error BUILD_UT
not defined.
What is causing this error? If I compile the following code
#if BUILD_UT
int x;
#endif
with g++ -c -Wall -Wextra -Wpedantic -Werror --std=c++11
I get no such error.
This causes the error:
g++ -c -Wundef -Werror
As discussed, the fix is to replace all occurrences of #if BUILD_UT
in the generated code with #ifdef BUILD_UT
, since BUILD_UT is an on/off switch.
Closing in favor of #374 and https://github.com/nasa/fprime/issues/2467.
The FPP autocoder generates code that can fail to compile in various scenarios.
BUILD_UT
.BUILD_UT
is not guaranteed to be set and thus#if BUILD_UT
should be replaced with#if (defined(BUILD_UT) && BUILD_UT)
if FW_SERIALIZABLE_TO_STRING || (defined(BUILD_UT) && BUILD_UT)
include <Fw/Types/String.hpp>
endif