相关疑难解决方法(0)

如何在mingw-w64 gcc 7.1中无需警告地打印size_t?

我在nuwen.net上使用minGW的mingw-w64(x64)分支.这是来自7.1版本的gcc:

gcc --version
gcc (GCC) 7.1.0
Run Code Online (Sandbox Code Playgroud)

我正在编译这个程序:

#include <stdio.h>

int main(void)
{
    size_t a = 100;
    printf("a=%lu\n",a);
    printf("a=%llu\n",a);
    printf("a=%zu\n",a);
    printf("a=%I64u\n",a);
}
Run Code Online (Sandbox Code Playgroud)

有警告和c11标准:

gcc -Wall -Wextra -Wpedantic -std=c11 test_size_t.c
Run Code Online (Sandbox Code Playgroud)

我收到这些警告:

   test_size_t.c: In function 'main':
    test_size_t.c:6:14: warning: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'size_t {aka long long unsigned int}' [-Wformat=]
      printf("a=%lu\n",a);
                ~~^
                %I64u
    test_size_t.c:6:14: warning: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'size_t {aka long long unsigned …
Run Code Online (Sandbox Code Playgroud)

c printf size-t

16
推荐指数
2
解决办法
3531
查看次数

如何在代码块上添加编译器标志

我一直在尝试编译一个我在网上找到的简单的多线程代码,以学习如何多线程.
要运行这段代码,我需要使用编译器标志:-pthread-std=c++0x.
但每当我尝试添加标志时,构建日志都不会显示它们被使用.

我已经尝试了一些在线的通用技巧,以使这些工作起作用,但它们都没有奏效.有人可以帮忙吗?

我已经尝试了在线的其他建议,以便为代码块添加编译器标志,但是当我这样做并检查构建日志时,它们都不会出现.

gcc codeblocks compiler-flags

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

标签 统计

c ×1

codeblocks ×1

compiler-flags ×1

gcc ×1

printf ×1

size-t ×1