gpt4 book ai didi

Declare string type for parameter in LLVM(声明LLVM中参数的字符串类型)

转载 作者:bug小助手 更新时间:2023-10-25 09:30:49 26 4
gpt4 key购买 nike



How would I declare a string parameter in the LLVM C++ API? For example, to declare a double parameter, I would do this:

如何在LLVMC++API中声明字符串参数?例如,要声明一个双精度参数,我将执行以下操作:


argTypes.push_back(Type::getDoubleTy(*context))

Is it possible to do this for a string? I understand that a string is an array of i8, but I just need to know the correct function call.

对于一根绳子来说,这样做是可能的吗?我知道字符串是由i8组成的数组,但我只需要知道正确的函数调用。


更多回答
优秀答案推荐

As you said, a string can be represented as a pointer to an array of i8 elements, so, for representing a string parameter, you would generally use i8* because parameters are typically pointers to some data:

正如您所说,字符串可以表示为指向i8元素数组的指针,因此,要表示字符串参数,通常使用i8*,因为参数通常是指向某些数据的指针:


argTypes.push_back(Type::getInt8PtrTy(*context));

Remember that this representation assumes that your strings are null-terminated (C strings). If you want to pass strings that also contain their length (C++ std::string wise), you'd usually pass a struct that contains both a pointer to the data (i8*) and the length (i64 or some other integer type).

请记住,这种表示形式假定您的字符串是以空值结尾的(C字符串)。如果您希望传递也包含其长度的字符串(C++std::字符串),您通常会传递一个同时包含指向数据的指针(i8*)和长度(i64或其他一些整数类型)的结构。


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com