我正在开发适用于各种口味Unix和Windows 32位和64位操作系统的应用程序.
我使用长双倍数据类型,当我做sprintf()和使用长的double与%lf在它然后它工作正常与Windows不给任何种类的错误,但在Solaris平台上它提供核心转储.
相同问题的示例代码如下.
void main(){
string size = "16622";
string sizeFact = "20";
long long sizeLongLong = strtoll(size);
int factInt = atoi(sizeFact);
long double sizeLongDouble = (long double) sizeLongLong/pow(2, factInt);
char buf[512];
sprintf(buf, "%.3lf %s", sizeLongDouble, "str");
}
如上所述,代码在Windows 32位和64位上工作正常,但是对于sprintf,它在Solaris上给予了核心.
我尝试在sprintf中的类型转换它工作正常.
sprintf(buf, "%.3lf %s", (double) sizeLongDouble, "str");
长双倍格式说明符是什么?
我在这里做的错误是什么,我使用错误的格式说明符,因为它是核心的?
为什么要在sprintf()中再次输入一次?