gpt4 book ai didi

c - 为什么当我转换为 float 时 gcc 总是报错?

转载 作者:太空宇宙 更新时间:2023-11-04 01:36:25 24 4
gpt4 key购买 nike

void init(void) 
{
glClearColor ((float)0.0, (float)0.0, (float)0.0, (float)0.0);
glShadeModel (GL_FLAT);
}

glClearColor 的参数是float。但是 gcc 总是给出警告:

main.c: In function ‘init’:
main.c:12: warning: passing argument 1 of ‘glClearColor’ as ‘float’ rather than ‘double’ due to prototype
main.c:12: warning: passing argument 2 of ‘glClearColor’ as ‘float’ rather than ‘double’ due to prototype
main.c:12: warning: passing argument 3 of ‘glClearColor’ as ‘float’ rather than ‘double’ due to prototype
main.c:12: warning: passing argument 4 of ‘glClearColor’ as ‘float’ rather than ‘double’ due to prototype

但我只是将数字转换为 float ,而不是 double ,不明白为什么。

我的操作系统是mac os 64bit,下面是makefile

UNAME := $(shell uname)

ifeq ($(UNAME), Darwin)
CFLAG := -framework GLUT -framework OpenGL -g -Wall -Wconversion
else
CFLAG := -lm -lglut -lGL -lGLU -g -Wall
endif

PUB_SRC := util.c plane.c dot.c linked_dots.c controller.c time_data.c
SRC := main.c $(PUB_SRC)
TEST_SRC := test.c $(PUB_SRC)

.PHONY : main
main: $(SRC)
gcc $(CFLAG) $(SRC)

.PHONY : test
test: $(TEST_SRC)
gcc $(CFLAG) $(TEST_SRC)

最佳答案

我认为您使用的是 GCC 3.x?在 GCC 3.x 中,-Wconversion 标志记录如下:

Warn if a prototype causes a type conversion that is different from what would happen to the same argument in the absence of a prototype. This includes conversions of fixed point to floating and vice versa, and conversions changing the width or signedness of a fixed point argument except when the same as the default promotion.

Also, warn if a negative integer constant expression is implicitly converted to an unsigned type. For example, warn about the assignment x = -1 if x is unsigned. But do not warn about explicit casts like (unsigned) -1.

[ link ]

据我了解,这个标志的最初目的是帮助检测从传统 C 迁移到 ANSI C 时的潜在问题,以及添加原型(prototype)可能导致问题的情况。 (老实说,在我看来,原型(prototype)本身触发警告比使用函数更有意义,但我可能遗漏了一些用途。 )

关于c - 为什么当我转换为 float 时 gcc 总是报错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13548421/

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