草庐IT

parameter-passing

全部标签

x86-64 : when are structs/classes passed and returned in registers? 上的 C++

假设Linux上的x86-64ABI,在C++中的什么条件下,结构传递给函数是在寄存器中还是在堆栈中?在什么情况下它们会返回到寄存器中?类(class)的答案会改变吗?如果它有助于简化答案,您可以假设一个参数/返回值并且没有浮点值。 最佳答案 ABI规范定义here.有更新版本可用here.我假设读者已经习惯了文档的术语,并且他们可以对基本类型进行分类。如果对象大小大于两个八字节,则在内存中传递:structfoo{unsignedlonglonga;unsignedlonglongb;unsignedlonglongc;//Com

c++ - 如何允许 std :string parameter to be NULL?

我有一个函数foo(conststd::string&str);如果您使用foo(NULL)调用它,它确实会崩溃。我该怎么做才能防止它崩溃? 最佳答案 std::string有一个带有constchar*参数的构造函数。当您将NULL传递给它时,构造函数将崩溃,并且当您编写foo(NULL)时会隐式调用该构造函数。我能想到的唯一解决办法就是重载foovoidfoo(conststd::string&str){//yourfunction}voidfoo(constchar*cstr){if(cstr==NULL)//dosometh

c++ - "a declaration shadows a parameter"是什么意思?

我正在尝试创建一个函数,该函数返回我将传递给它的整数的两倍。我的代码收到以下错误消息:declarationof'intx'shadowsaparameterintx;"这是我的代码:#includeintdoublenumber();usingnamespacestd;intdoublenumber(intx)//>a;doublenumber(a);return0;} 最佳答案 您将x作为参数,然后尝试将其也声明为局部变量,这就是对“阴影”的提示。 关于c++-"adeclarati

c++ - 输入参数传递 : is there a size threshold for efficient pass-by-value?

在C++中,当输入参数复制成本低时(例如,int、float等),它通常被传递只需按值。相反,复制起来并不便宜的输入“观察到的”参数(例如std::string)由const&传递。我想知道像POD这样的类型表示具有int坐标的二维vector,例如structVec2i{intX;intY;};在32位MSVC编译器上,它只有8个字节(2*sizeof(int))。您会按值还是按const&传递它?那么Vec2d有double类型的坐标呢?(在MSVC上它将是2*sizeof(double),所以2*8=16字节。)是否有“大小阈值”(例如16字节?)用于放置一行并说:“对于超过X大

c++ - std::apply forward parameters 如何在没有显式 std::forward 的情况下应用?

考虑std::apply的可能实现:namespacedetail{templateconstexprdecltype(auto)apply_impl(F&&f,Tuple&&t,std::index_sequence){returnstd::invoke(std::forward(f),std::get(std::forward(t))...);}}//namespacedetailtemplateconstexprdecltype(auto)apply(F&&f,Tuple&&t){returndetail::apply_impl(std::forward(f),std::forw

c++ - g++ 编译器错误 : couldn't deduce template parameter ‘_Funct’

我正在尝试使用ANSIC++for_each语句迭代并打印标准vector的元素。如果我让for_each调用一个非重载函数,它会工作,但如果我让它调用一个重载函数,则会产生编译器错误。这是一个最小的测试程序,用于显示编译器错误发生的位置:#include#include#includestructS{charc;inti;};std::vectorv;voidprint_struct(intidx);voidprint_struct(conststructS&s);//f:anon-overloadedversionoftheprecedingfunction.voidf(const

C++ "error: passing ' const std::map<int, std::basic_string<char>>' as ' this' argument of ..."

使用以下代码(为简洁起见摘录):颜色.h:classcolor{public:color();enumcolorType{black,blue,green,cyan,red,magenta,brown,lightgray,nocolor};colorTypegetColorType();voidsetColorType(colorTypecColortype);stringgetColorText()const;private:colorTypecColortype=nocolor;mapcolors={{black,"black"},{blue,"blue"},{green,"gre

c++ - 模板编译失败 : 'double' is not a valid type for a template constant parameter

templateclassLowerBoundedType{};templateclassvectorelement{};templateclassvectorelement{typedefLowerBoundedTypetype;};有错误:error:'double'isnotavalidtypeforatemplateconstantparameter 最佳答案 唯一对非类型模板参数有效的数字类型是整数和枚举。因此,您不能拥有double类型的非类型模板参数。 关于c++-模板编译

windows - Build.xml 给出问题。 ."CreateProcess error=87, The parameter is incorrect"

我试图在Windows环境中使用ant构建脚本来执行我的java程序。但是我遇到了以下问题。这是在linux环境中工作的。[1]init:compile:stockquote:[java]C:\wso2esb-4.0.0-SNAPSHOT\samples\axis2Client\build.xml:128:java.io.IOException:Cannotrunprogram"C:\ProgramFiles\Java\jdk1.6.0_20\jre\bin\java.exe":CreateProcesserror=87,Theparameterisincorrect[java]ato

windows - CMD/windows 批处理 : how to pass a double quote and a larger than sign in a command argument?

我可以通过多种方式将双引号和大于号传递给任何命令:'"'、"\""、">"但是当我尝试将它们一起传递时C:\>echo"\">"Thesystemcannotfindthepathspecified.与"\"\>"相同。我可以使用单引号使其工作,但由于我已经处理了很多引号,所以我想保留所有内容双引号内。有什么办法可以避免吗?我在windows7上,但我相信这是一些向后兼容性“功能”,所以不确定此信息是否相关。编辑1:我认为Endoro的答案是正确的……但这并没有那么简单。CMD对^>的处理方式不同,具体取决于字符串中是否存在转义双引号。任何人都知道为什么?还是不同的转义方法?C:\>s