相关疑难解决方法(0)

如何printf uint64_t?失败:"格式中的虚假尾随'%'

我写了一个非常简单的printf uint64_t测试代码:

#include <inttypes.h>
#include <stdio.h>

int main()
{
  uint64_t ui64 = 90;
  printf("test uint64_t : %" PRIu64 "\n", ui64);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

我使用ubuntu 11.10(64位)和gcc版本4.6.1进行编译,但失败了:

main.cpp: In function ‘int main()’:
main.cpp:9:30: error: expected ‘)’ before ‘PRIu64’
main.cpp:9:47: warning: spurious trailing ‘%’ in format [-Wformat]
Run Code Online (Sandbox Code Playgroud)

c c++

132
推荐指数
1
解决办法
10万
查看次数

如何将64位整数打印为十六进制?

使用以下代码,我尝试使用输出unit64_t变量的值printf().使用gcc编译代码,返回以下警告:

警告:格式'%x'需要'unsigned int'类型的参数,但参数2的类型为'uint64_t'[ - Wformat =]

代码:

#include <stdio.h>
#include <stdint.h>

int main ()
{
    uint64_t val = 0x1234567890abcdef;
    printf("val = 0x%x\n", val);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

val = 0x90abcdef
Run Code Online (Sandbox Code Playgroud)

预期产量:

val = 0x1234567890abcdef
Run Code Online (Sandbox Code Playgroud)

如何使用printf()?输出64位值作为十六进制整数?x在这种情况下,说明符似乎是错误的.

c 64-bit gcc

23
推荐指数
2
解决办法
8万
查看次数

C++/C int32_t和printf格式:%d或%ld?

在某些平台上,int32_t(来自stdint.h)是long int,但在其他平台上,它可能是int.当我想使用时printf,我如何确定"%ld""%d"应该使用哪种格式?

或者,也许,我应该强制将其转换为如下所示:

int32_t m;
m = 3;
printf ("%ld\n", (long)m);
Run Code Online (Sandbox Code Playgroud)

但这种解决方案很乏味.有什么建议?

c c++ printf

8
推荐指数
1
解决办法
1万
查看次数

错误的printf类型仍然打印正确的值

我刚刚遇到这种奇怪的情况,我无法解释它.我真的很好奇,最重要的事情发生了什么.我有这个示例代码:

#include <stdio.h>
#include <stdint.h>

int main()
{
    int64_t qty = 900;
    double  p   = 74.45;

    printf( "%f|%ld\n", p, qty );
    printf( "%f|%ld\n", qty, p );
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

请注意,在第二个printf中,我提供了错误订单中的参数,更不用说类型错误了.但是,我仍然得到两个CORRECT输出?奇怪的是......用gcc 7.2编译:

$ ./a.out
74.450000|900
74.450000|900
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?

c printf

6
推荐指数
1
解决办法
59
查看次数

什么是NSString的int64_t格式说明符

我找不到合适的格式说明符 int64_t

int64_t var;

[NSString stringWithFormat:@"value is: %?? ",var];
Run Code Online (Sandbox Code Playgroud)

objective-c ios

5
推荐指数
1
解决办法
4661
查看次数

int64_t的宽度是64位吗?

对于以下代码

static inline float fix2float(int64_t f)
{
    return (float)f / (1 << 60); // <-- error here
}
Run Code Online (Sandbox Code Playgroud)

编译器给了我这些警告.

warning: left shift count >= width of type
warning: division by zero
Run Code Online (Sandbox Code Playgroud)

当64> 60时,为什么编译器会发出这些警告?

c x86 gcc

2
推荐指数
1
解决办法
490
查看次数

返回的uint64_t似乎被截断了

我想返回一个,uint64_t但结果似乎被截断:

lib.c:

uint64_t function()
{
    uint64_t timestamp = 1422028920000;
    return timestamp;
}
Run Code Online (Sandbox Code Playgroud)

main.c:

uint64_t result = function();
printf("%llu  =  %llu\n", result, function());
Run Code Online (Sandbox Code Playgroud)

结果:

394745024  =  394745024
Run Code Online (Sandbox Code Playgroud)

在编译时,我收到一个警告:

warning: format '%llu' expects argument of type 'long long unsigned int', but argument 2 has type 'uint64_t' [-Wformat]
warning: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'int' [-Wformat]
Run Code Online (Sandbox Code Playgroud)

为什么编译器认为我的函数的返回类型是int?我们怎样才能解释打印的reslut与函数发送的值不同function()

c 64-bit return-type uint64

2
推荐指数
1
解决办法
1498
查看次数

如何在gcc中打印UINT64_t?

为什么这段代码不起作用?

#include <stdio.h>
main()
{
    UINT64_t ram = 90;
    printf("%d""\n", ram);
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

In function \u2018main\u2019
error: \u2018UINT64_t\u2019 undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: expected \u2018;\u2019 before \u2018ram\u2019
Run Code Online (Sandbox Code Playgroud)

c unix function

2
推荐指数
1
解决办法
2万
查看次数

这是LLVM中的错误吗?

我正在编译这段代码(使用clang 3.4.2):

#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>

typedef struct __entry {
    char *name;
    int value;
} entry;

int main(int argv, char **argc) {
            printf("Size of entry: %lu\n", sizeof(entry));
        entry *entry = malloc(sizeof(entry));
        printf("entry is at %lu\n", (uint64_t) entry);
}
Run Code Online (Sandbox Code Playgroud)

我收到这个bitcode:

define i32 @main(i32 %argv, i8** %argc) #0 {
entry:
  %argv.addr = alloca i32, align 4
  %argc.addr = alloca i8**, align 8
  %entry1 = alloca %struct.__entry*, align 8
  store i32 %argv, i32* %argv.addr, align 4
  store i8** %argc, i8*** %argc.addr, …
Run Code Online (Sandbox Code Playgroud)

c sizeof llvm clang

-1
推荐指数
1
解决办法
93
查看次数

标签 统计

c ×8

64-bit ×2

c++ ×2

gcc ×2

printf ×2

clang ×1

function ×1

ios ×1

llvm ×1

objective-c ×1

return-type ×1

sizeof ×1

uint64 ×1

unix ×1

x86 ×1