为什么 Release 不通过 Debug 进行构建,而是仅针对使用相同源文件的项目之一进行构建?
Why does Release not build though Debug goes, but only for one of the projects using the same source file?
Xilinx SDK 的 C++ 编译器,为 Zynq SoC(一个 ARM 内核)编译代码,抱怨未初始化的变量,但仅在 Release 版本中,且仅针对一个项目。调试很好,对于链接到同一源文件的另一个项目,调试和发布版本都很好 newthing.cpp。我看不到 project-dependent #ifdef。据我所知,所有构建设置都是相同的,当然调试信息和优化在 Release 和 Debug 之间是不同的,但在项目之间没有区别。我们中的一个人怀疑 Xilinx 工具中存在错误,但除了 IDE.
中的 makefile 或 Build Settings 等明显位置之外,其他地方可能存在细微差别。
问题出在这样的代码中(在 newthing.cpp 中):
Result R;
GetSomeResult(7, R);
PushData(R.blip); <== compiler whines: using uninitialized var
其中 newthing.h header 定义
struct Result
{
int blip;
int bloop;
};
并且在 newthing.cpp 的其他地方定义的结果结构是这样填充的:
int GetSomeResult(int n, Result &res)
{
res.blip = n + 100;
res.bloop = 50;
return n;
}
请注意,我忽略了 GetSomeResult 的 return 值,但我怀疑这是否相关。
这是假阴性。
如果可以,请在将结构传递给 GetSomeResult
之前对结构进行零初始化:
Result R = {};
GetSomeResult(7, R);
PushData(R.blip);
如果这不可行(在极少数情况下可能太 slow/wasteful),您将不得不使用构建系统或 #pragma
关闭 warning/error对于这个翻译单元。
如果可能,您可能还希望尝试使用更新版本的编译器。
当然,如果您放弃类似 C 的方法而是写成:
,您的代码会更加地道并且不易受此问题的影响
Result GetSomeResult(const int n)
{
Result res;
res.blip = n + 100;
res.bloop = 50;
return res;
}
// const Result R = GetSomeResult(7);
// PushData(R.blip);
Xilinx SDK 的 C++ 编译器,为 Zynq SoC(一个 ARM 内核)编译代码,抱怨未初始化的变量,但仅在 Release 版本中,且仅针对一个项目。调试很好,对于链接到同一源文件的另一个项目,调试和发布版本都很好 newthing.cpp。我看不到 project-dependent #ifdef。据我所知,所有构建设置都是相同的,当然调试信息和优化在 Release 和 Debug 之间是不同的,但在项目之间没有区别。我们中的一个人怀疑 Xilinx 工具中存在错误,但除了 IDE.
中的 makefile 或 Build Settings 等明显位置之外,其他地方可能存在细微差别。问题出在这样的代码中(在 newthing.cpp 中):
Result R;
GetSomeResult(7, R);
PushData(R.blip); <== compiler whines: using uninitialized var
其中 newthing.h header 定义
struct Result
{
int blip;
int bloop;
};
并且在 newthing.cpp 的其他地方定义的结果结构是这样填充的:
int GetSomeResult(int n, Result &res)
{
res.blip = n + 100;
res.bloop = 50;
return n;
}
请注意,我忽略了 GetSomeResult 的 return 值,但我怀疑这是否相关。
这是假阴性。
如果可以,请在将结构传递给 GetSomeResult
之前对结构进行零初始化:
Result R = {};
GetSomeResult(7, R);
PushData(R.blip);
如果这不可行(在极少数情况下可能太 slow/wasteful),您将不得不使用构建系统或 #pragma
关闭 warning/error对于这个翻译单元。
如果可能,您可能还希望尝试使用更新版本的编译器。
当然,如果您放弃类似 C 的方法而是写成:
,您的代码会更加地道并且不易受此问题的影响Result GetSomeResult(const int n)
{
Result res;
res.blip = n + 100;
res.bloop = 50;
return res;
}
// const Result R = GetSomeResult(7);
// PushData(R.blip);