相关疑难解决方法(0)

GCC在编译时不会发出警告

以下代码编译并运行但我在编译时会发出警告:

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

int main(void){

  int x = 10;
  printf("%p\n",&x);

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

GCC,来自使用命令行参数的在线编译器

-Wall -std=gnu99 -O2 -o a.out source_file.c -pedantic -Wextra
Run Code Online (Sandbox Code Playgroud)

编译时发出以下警告

source_file.c: In function ‘main’:
source_file.c:7:3: warning: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int *’ [-Wformat=]
   printf("%p\n",&x);
Run Code Online (Sandbox Code Playgroud)

因为我之前没有添加一个(void*)强制转换,因为我在 编译时需要一个类型&x%p.But的参数void*

gcc SO.c -o so -Wall -Wextra -pedantic -std=c11
Run Code Online (Sandbox Code Playgroud)

要么

gcc SO.c -o so -Wall -Wextra -pedantic -std=c99
Run Code Online (Sandbox Code Playgroud)

要么

gcc SO.c -o …
Run Code Online (Sandbox Code Playgroud)

c gcc gnu

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

打印整数值时出现意外输出

#include<stdio.h>
void main()
{
   int i = 5;
   printf("%p",i);
}
Run Code Online (Sandbox Code Playgroud)

我试图在Linux上使用GCC编译器编译这个程序,在编译程序时会发出警告说

%p expects a void* pointer 
Run Code Online (Sandbox Code Playgroud)

当运行时输出为46600x3.

但是当我使用网站codingground.tutorialspoint.com在线编译时,我得到一个输出等于0x5 即十六进制输出,有人可以解释原因吗?

c gcc pointers compiler-errors

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

gcc:printf和long double导致输出错误.[C - 类型转换混乱]

我是C的新手.我尝试为Vector编写函数,但肯定有问题.
这是代码:

/* Defines maths for particles. */

#include <math.h>
#include <stdio.h>

/* The vector struct. */
typedef struct {
    long double x, y, z;
} Vector;

Vector Vector_InitDoubleXYZ(double x, double y, double z) {
    Vector v;
    v.x = (long double) x;
    v.y = (long double) y;
    v.z = (long double) z;
    return v;
}

Vector Vector_InitDoubleAll(double all) {
    Vector v;
    v.x = v.y = v.z = (long double) all;
    return v;
}


Vector Vector_InitLongDXYZ(long double x, long double y, …
Run Code Online (Sandbox Code Playgroud)

c gcc

4
推荐指数
2
解决办法
9850
查看次数

标签 统计

c ×3

gcc ×3

compiler-errors ×1

gnu ×1

pointers ×1