草庐IT

c++ - 无法使此代码在 MSVC 2015 和 GCC 7.3 之间交叉编译

当我为我的项目编写代码时,我发现了一个非常奇怪的情况,我的C++11代码无法在GCC7.3和之间交叉编译>MSVC2015。案例基本上是这样的://.HfiletemplatestructOuter{Xx={};templatestructInner{Yy={};Inner&operator++();};};//.INLfiletemplatetemplateinlineOuter::Inner&Outer::Inner::operator++(){++y;return*this;}//.CPPfile#includeintmain(){Outer::Innera;++a;std::c

c++ - MSVC中自动生成FMA指令

MSVC多年来一直支持AVX/AVX2指令,并且根据thismsdnblogpost,可以自动生成fused-multiply-add(FMA)说明。然而,以下函数都无法编译为FMA指令:floatfunc1(floatx,floaty,floatz){returnx*y+z;}floatfunc2(floatx,floaty,floatz){returnstd::fma(x,y,z);}更糟糕的是,std::fma不是作为单个FMA指令实现的,它执行得非常糟糕,比普通的x*y+z慢得多(std::fma的糟糕性能是如果实现不依赖于FMA指令,这是预期的)。我用/arch:AVX2/O

c++ - MSVC12 认为从 std::array 派生的聚合不是 pod

鉴于以下#includestructlitmusfinal:std::array{};static_assert(std::is_pod>::value,"notpod");//thisfailsonMSVC:static_assert(std::is_pod::value,"notpod");以下编译器同意litmus是pods:clang++版本3.5(中继线198621)http://coliru.stacked-crooked.com/a/7add7a2fe58a7e38g++4.8.1http://coliru.stacked-crooked.com/a/74cfe97f06

c++ - MSVC++ : Strangeness with unsigned ints and overflow

我有以下代码:#includeusingnamespacestd;intmain(intargc,char*argv[]){stringa="a";for(unsignedinti=a.length()-1;i+1>=1;--i){if(i>=a.length()){cerr如果我在完全优化的MSVC中编译,我得到的输出是“-1?”。如果我在Debug模式下编译(没有优化),我不会得到任何输出(预期。)我认为标准保证无符号整数以可预测的方式溢出,因此当i=(unsignedint)(-1)、i+1=0时,循环条件i+1>=1失败。相反,测试以某种方式通过了。这是编译器错误,还是我在某处

c++ - gcc 和 clang 抛出 "no matching function call"但 msvc (cl) 编译并按预期工作

我写了一个小的函数模板,将不同的容器连接到一个新的容器中:#include#include#include#include#includenamespaceimpl{templatevoidjoin(OutIteratoriterator,constContainer&container,constContainers&...containers){for(constauto&item:container)*iterator++=item;join(iterator,containers...);//gccandclangcannotresolvethiscall}templatevo

c++ - MSVC 中的复合文字

在GCC中,我可以这样做:(CachedPath){ino}inode->data=(structData)DATA_INIT;哪里:structCachedPath{Inoino;};typedefint8_tDepth;structData{Offsetsize;Blknoroot;Depthdepth;};#defineDATA_INIT{0,-1,0}MSVC为这些类型的转换给出了以下错误:errorC2143:syntaxerror:missing';'before'{'我如何在MSVC中执行此操作?请注意,代码已从C99转换而来,我为此使用了指定的初始化程序,然后以类似的方

c++ - MSVC++ 中的无限

我正在使用MSVC++,我想在我的代码中使用特殊值INFINITY。在MSVC++中用于无穷大的字节模式或常量是什么?为什么1.0f/0.0f的值看起来是0?#include#includeintmain(){floatzero=0.0f;floatinf=1.0f/zero;printf("%f\n",inf);//1.#INF00printf("%x\n",inf);//whyisthis0?printf("%f\n",zero);//0.000000printf("%x\n",zero);//0} 最佳答案 使用numeric

c++ - 如何分两步运行 MSVC 预处理器和编译器?

我想在不调用预处理器的情况下运行MicrosoftVisualStudio编译器cl.exe。这可能吗?我认为简单地编译预处理的源代码(使用/c标志)会使预处理器运行为空操作,但显然情况并非如此。我做了一些基准测试。这是一个小源文件(main.cpp),其中仅包含一些代码:#include#include#include以下是一些不同的编译器调用及其时间:1:cl/cmain.cpp~1.02s2:cl/EPmain.cpp>main-preprocessed.cpp~0.5s3:cl/cmain-preprocessed.cpp~0.75s编译预处理后的源代码似乎已经快了一点(预处理

c++ - 为什么此代码会产生与 MSVC 的无效对齐?

我已经在ideone.com上测试了这段代码,它按预期输出了16。但是,当我在VisualStudio2013中尝试时,它显示8。是错误还是编译器缺少C++11支持?#include#includeusingnamespacestd;usingfloat_pack=aligned_storage::type;intmain(){cout::value我使用了alignment_of,因为MSVC不支持alignof。编辑:我发现我无法使16与aligned_storage对齐。但是为什么这个片段没问题?#include#include#includeusingnamespacestd;

c++ - 删除的构造函数 - MSVC 报告错误,Clang 没有

考虑以下代码:classSILPassPipelinePlanfinal{public:SILPassPipelinePlan()=default;~SILPassPipelinePlan()=default;SILPassPipelinePlan(constSILPassPipelinePlan&)=default;SILPassPipelinePlan(SILPassPipelinePlan&&)=delete;SILPassPipelinePlanx(){SILPassPipelinePlanP;returnP;}};intmain(){return0;}MSVC报如下错误:1>