草庐IT

right-align

全部标签

c++ - 如何将 __declspec(align(16)) 与模板一起使用?

我正在尝试使我的class16-byte与__declspec(align(16))对齐;但是它是一个模板类。如果我将__declspec(align(16))放在模板关键字之前,它告诉我那里不允许使用可变属性。如果我将它放在class关键字之前,整个类将变得无效并且所有方法都会显示错误。那么它是怎么做到的呢? 最佳答案 这个实现可能会回答这个请求:templatestructalignas(Align)aligned_storage{Ta;Tb;};templatestructaligned_storage_members{ali

c++ - GCC 7,aligned_storage 和 "dereferencing type-punned pointer will break strict-aliasing rules"

我编写的代码在GCC4.9、GCC5和GCC6中没有警告。它在一些较旧的GCC7实验快照(例如7-20170409)中也没有警告。但在最近的快照(包括第一个RC)中,它开始产生关于别名的警告。代码基本上可以归结为:#includestd::aligned_storage::typestorage;intmain(){*reinterpret_cast(&storage)=42;}使用最新的GCC7RC编译:$g++-Wall-O2-cmain.cppmain.cpp:Infunction'intmain()':main.cpp:7:34:warning:dereferencingtyp

c++ - Cocos2d-x 3 测试版 : polygon not drawn right

我按照建议使用DrawNode来绘制多边形,但问题是它没有正确绘制,因为我喜欢我附加所需多边形形状的图像和一个输出错误的代码输出。代码:if(sprite&&sprite->init()){sprite->setTextureRect(Rect(0,0,200,200));sprite->autorelease();autodraw=DrawNode::create();{PointBlock1[]={Point(0,0),Point(30,0),Point(50,10),Point(80,10),Point(100,0),Point(200,0),Point(200,40),Poin

c++ - 检查数组是否为 'right' (C++)

ArightarrayLet'sassumewehaveanarraywithanNlength,madeofcapitallettersA,B,andC.Wecallthearray'arightarray'ifbetweeneverytwoCletterswhichcomeoneafteranotherinthearray,therearemoreAlettersthanBletters.Myjobistodiscoverwhetherornotagivenarrayis'right'andifso,Ishouldprintout"RIGHT",elseIshouldprintfo

c++ - struct S { int align; 之间的区别}; (在 struct 关键字之后命名)和 struct { int align; } S; (结构定义后的名称)

#includestructHeader{unsignedlonglongintalignment;};intmain(void){structHeaderheader;//note:wecanloosethe'struct'inC++structHeader*pheader=&header;return0;}上面的程序在C和C++中都能完美编译。但是当我将Header结构更改为:struct{unsignedlonglongintalignment;}Header;它失败并在C中显示以下消息:错误:“Header”的存储大小未知在C++中:error:aggregate‘main()

c++ - "BUS_ADRALN - Invalid address alignment"错误是什么意思?

我们在HPUX上,我的代码在C++中。我们得到了BUS_ADRALN-Invalidaddressalignment在我们的函数调用中的可执行文件中。这个错误是什么意思?相同的功能运行了很多次,然后突然出现了核心转储。在GDB中,当我尝试打印它不在上下文中的对象值时。知道在哪里检查吗? 最佳答案 您遇到了数据对齐问题。这可能是由于尝试通过某种错误的指针读取或写入造成的。数据对齐问题是指指针指向的地址未正确“对齐”。例如,某些体系结构(例如旧的Cray2)要求任何从内存中读取除单个字符以外的任何内容的尝试只能通过指针值的最后3位为0的

c++ - 警告 #13212 : Reference to ebx in function requiring stack alignment

我正在尝试使用ICC2018编译以下代码:__asm{movebx,xx;xxaddresstoregisters}其中xx是int16类型。这是我的函数中的第一条指令。我使用上面的汇编代码收到以下警告:警告#13212:在需要堆栈对齐的函数中引用ebx令人惊讶的是,当我用eax或esi替换ebx时,我看到警告消失了。我不明白为什么我只看到ebx的问题,据我所知,ebx和eax都具有相同的架构(32位寄存器)。另外,当我用ICC2013编译相同的代码时,我没有看到警告。谁能帮我解决这个警告?谢谢! 最佳答案 如果需要额外对齐,所选平

c++ - 对齐 : warning C4316 in all classes that have aligned members

今天我遇到了很多麻烦,因为我跟踪了一个非常隐蔽的腐败漏洞。我想如果我真的注意警告就不会那么难找到它,但由于找不到有关为什么弹出此特定警告的相关信息,我让它滑动了,这是一个错误。所以这是VisualStudio2013给我的有罪警告:warningC4316:objectallocatedontheheapmaynotbealigned16它是在通过const引用将align(16)临时传递给构造函数时生成的,如以下代码所示:classVector{};__declspec(align(16))classVectorA{};classShape{public:Shape(constVec

c++ - 为什么 shared_ptr 可以访问 ingoring "protected access right"

我用shared_ptr做了一些测试,我想不出下面的问题。我刚开始学习boost库。有谁能告诉我原因吗?#include#includeclassA{public:virtualvoidsing(){std::coutpa(newB());pa->sing();deletestatic_cast(pa.get());deletepa.get();//thislinehasaproblemerrorC2248:“A::~A”:can'taccessprotectedmemmber(declaredinclass“A")return0;}intmain(){foo();return0;}但

菜鸟记录:c语言实现PAT甲级1005--Spell It Right

 非常简单的一题了,但还是交了两三次,原因:对数组的理解不足;对数字和字符之间的转换不够敏感。这将在下文中细说。Givenanon-negativeinteger N,yourtaskistocomputethesumofallthedigitsof N,andoutputeverydigitofthesuminEnglish.InputSpecification:Eachinputfilecontainsonetestcase.Eachcaseoccupiesonelinewhichcontainsan N (≤10100).OutputSpecification:Foreachtestca