我已经开始了一个新项目,并决定确保在启用/ Wall选项的情况下干净地构建它.唯一的问题是并非所有第三方库(如boost)在没有警告的情况下编译,所以我在共享头中使用了这个:
#pragma warning(push)
#pragma warning(disable:4820)
#pragma warning(disable:4619)
#pragma warning(disable:4668)
#pragma warning(disable:4625)
#pragma warning(disable:4626)
#pragma warning(disable:4571)
#pragma warning(disable:4347)
#pragma warning(disable:4640)
#pragma warning(disable:4365)
#pragma warning(disable:4710)
#pragma warning(disable:4820)
#pragma warning(disable:4350)
#pragma warning(disable:4686)
#pragma warning(disable:4711)
#pragma warning(disable:4548)
#include <boost/array.hpp>
#include <boost/assert.hpp>
#include <boost/assign.hpp>
#include <boost/bind.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <boost/function.hpp>
#include <boost/integer.hpp>
#include <boost/optional.hpp>
#include <boost/regex.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/utility.hpp>
#include <boost/variant.hpp>
#pragma warning(pop)
Run Code Online (Sandbox Code Playgroud)
这很好用,但每次添加新的boost标头时,我都要将它们生成的警告添加到列表中.有没有办法说禁用这段代码的所有警告?

http://en.wikipedia.org/wiki/Pragma_once
当所有这些编译器都支持时,我还应该使用包含保护#pragma once吗?
很多关于堆栈溢出的响应都表示要使用它们兼容,但我不确定它是否仍然是真的.今天哪些编译器不支持#pragma once?
我不确定在它成为widley之前使用两者是否只是一个推荐,或者是否仍然有很好的理由使用这两种方法.
什么时候只使用#pragma once会导致问题的例子?
为了将"todo"项添加到我的代码中,我想在编译器输出中添加一条消息.
我希望它看起来像这样:
c:/temp/main.cpp(104): TODO - add code to implement this
Run Code Online (Sandbox Code Playgroud)
为了利用Visual Studio构建输出功能,通过双击导航到相应的行.
但__LINE__宏似乎扩展到了一个int不允许写作的
#pragma message( __FILE__ "("__LINE__"): ..." )
Run Code Online (Sandbox Code Playgroud)
会有另一种方式吗?
我有一个网站,我继承了维护,这是一个很大的毛病.
我正在做的一件事就是提高性能.除此之外,我正在Expires为图像添加标题.
现在,有一些图像是通过PHP文件提供的,我注意到它们确实有Expires标题,但每次都会加载它们.
看看响应标题,我看到了这个:
Expires Wed, 15 Jun 2011 18:11:55 GMT
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma no-cache
Run Code Online (Sandbox Code Playgroud)
这显然解释了这个问题.
现在,我看了整个代码库,并没有在任何地方说"pragma"..htaccess似乎没有任何相关的东西.
什么想法可以设置那些"pragma"(和"缓存控制")标题,我怎么能避免它?
我的背景是C#,但我必须维护一些遗留(MS)C++.在那个代码库中我弄明白:
#pragma comment(lib, "OtherLib700.lib")
Run Code Online (Sandbox Code Playgroud)
其中700是一些版本.除了lib是一个具有相同名称的DLL.
我首先想到的程序将依赖于DLL,但在从系统中删除后,程序仍然有效.但是有一个更新版本的DLL,名为OtherLib900 ...
似乎程序"包含"了lib的代码,因此它不再依赖于外部DLL.(或者程序'自动'使用较新的DLL ...)
哪一个是正确的?是否有办法进一步确认"假设"?
禁用警告的语法如下:
#pragma warning disable 414, 3021
Run Code Online (Sandbox Code Playgroud)
或者,更一般地表达:
#pragma warning disable [CSV list of numeric codes]
Run Code Online (Sandbox Code Playgroud)
是否有这些数字代码的列表以及它们要抑制的警告的描述?令我懊恼的是,我似乎无法通过谷歌找到它.
我用c#创建了第一个项目.我有很多警告错误,所有这些警告错误都是单一错误(内部编译器错误.有关详细信息,请参阅控制台日志.)
为了减少警告错误,我使用了#pragma Warning disable.#pragma warning恢复有问题代码的正面和背面.
我怀疑在我的最终版本中我应该保留#pragma warning disable&restore,因为它在程序中; 还是我需要删除它?例如:
#pragma warning disable
if (Displayer.instance != null && CTR.Tore== "Keepit")
{
Displayer.instance.SetFielderProfile (i);
}
#pragma warning restore
Run Code Online (Sandbox Code Playgroud)
对于最终版本,我是否需要删除它?
我们最近启用-Wall了一个项目.当GCC处于4.7或更高(或Clang)时启用它,因为我们可以GCC diagnostic用来管理提升警告的输出.我们希望从源代码管理它们,而不是通过命令行参数.(我们不想污染命令行,或者要求库用户重新发现需要的内容).
下GCC 4.8和5.1,我们正在捕捉的用于GCC诊断块中禁用的警告-Wunused-variable,-Wunused-value,-Wunused-function和-Wunknown-pragmas.两个GCC都接受-fopenmp,并且都定义_OPENMP为响应它,所以我相当肯定它我们永远不应该看到-Wunknown-pragmas响应#prgam omp ...(它被禁用,但它不是未知).
g++ -DNDEBUG -g2 -O3 -Wall -march=native -pipe -c nbtheory.cpp
nbtheory.cpp:655:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
#pragma omp parallel
^
nbtheory.cpp:656:0: warning: ignoring #pragma omp sections [-Wunknown-pragmas]
#pragma omp sections
^
...
Run Code Online (Sandbox Code Playgroud)
在这种特殊情况下,文件nbtheroy.cpp具有以下保护措施以帮助管理该警告(仅显示相关部分,但您可以从GitHub链接中查看所有内容):
// Defines GCC_DIAGNOSTIC_AWARE if GCC 4.7 or above.
#include <misc.h> …Run Code Online (Sandbox Code Playgroud) 我是CUDA的新手,我无法理解循环展开.我写了一段代码来理解这项技术
__global__ void kernel(float *b, int size)
{
int tid = blockDim.x * blockIdx.x + threadIdx.x;
#pragma unroll
for(int i=0;i<size;i++)
b[i]=i;
}
Run Code Online (Sandbox Code Playgroud)
以上是我的核心功能.在main我称之为下面
int main()
{
float * a; //host array
float * b; //device array
int size=100;
a=(float*)malloc(size*sizeof(float));
cudaMalloc((float**)&b,size);
cudaMemcpy(b, a, size, cudaMemcpyHostToDevice);
kernel<<<1,size>>>(b,size); //size=100
cudaMemcpy(a, b, size, cudaMemcpyDeviceToHost);
for(int i=0;i<size;i++)
cout<<a[i]<<"\t";
_getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是否意味着我有size*size= 10000个线程运行来执行程序?在展开循环时是否创建了100个?
到目前为止,我已经达到了:
#define ADEFINE "23"
#pragma message ("ADEFINE" ADEFINE)
Run Code Online (Sandbox Code Playgroud)
哪个有效,但如果ADEFINE不是字符串怎么办?
#define ADEFINE 23
#pragma message ("ADEFINE" ADEFINE)
Run Code Online (Sandbox Code Playgroud)
原因:
警告:格式错误的'#pragma message',被忽略
理想情况下,我希望能够处理任何值,包括undefined.