gpt4 book ai didi

c - 警告 : initializer element is not computable at load time

转载 作者:太空宇宙 更新时间:2023-11-04 07:11:03 26 4
gpt4 key购买 nike

在以下情况下,我无法理解 gcc -pedantic 输出:

$ gcc -pedantic parse.c -lpopt
parse.c: In function ‘main’:
parse.c:19:7: warning: initializer element is not computable at load time
{ "bps", 'b', POPT_ARG_INT, &speed, 0,
^
parse.c:20:7: warning: initializer element is not computable at load time
"signaling rate in bits-per-second", "BPS" },
^
parse.c:27:7: warning: initializer element is not computable at load time
{ "raw", 'r', 0, &raw, 0,
^
parse.c:28:7: warning: initializer element is not computable at load time
"don't perform any character conversions" },
^

使用以下 C 代码(取自 here):

$ cat parse.c
#include <popt.h>

int main(int argc, const char *argv[]) {
char c; /* used for argument parsing */
int speed = 0; /* used in argument parsing to set speed */
int raw = 0; /* raw mode? */
struct poptOption optionsTable[] = {
{ "bps", 'b', POPT_ARG_INT, &speed, 0,
"signaling rate in bits-per-second", "BPS" },
{ "crnl", 'c', 0, 0, 'c',
"expand cr characters to cr/lf sequences" },
{ "hwflow", 'h', 0, 0, 'h',
"use hardware (RTS/CTS) flow control" },
{ "noflow", 'n', 0, 0, 'n',
"use no flow control" },
{ "raw", 'r', 0, &raw, 0,
"don't perform any character conversions" },
{ "swflow", 's', 0, 0, 's',
"use software (XON/XOF) flow control" } ,
POPT_AUTOHELP
{ NULL, 0, 0, NULL, 0 }
};
}

完全相同的代码可以使用 -ansi-std=c89 进行编译。为什么 -pedantic 选项失败?

使用:

$ gcc --version
gcc (Debian 4.9.1-19) 4.9.1
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ apt-cache policy libpopt-dev
libpopt-dev:
Installed: 1.16-10
Candidate: 1.16-10
Version table:
*** 1.16-10 0
500 http://ftp.fr.debian.org/debian/ jessie/main amd64 Packages
100 /var/lib/dpkg/status

最佳答案

因为可变速度是在栈上分配的,所以它的地址在编译时是未知的。只有当 main() 正在执行时,它的地址才会被知道。变量 raw 也一样。与任何优秀的编译器一样,您的编译器的错误消息不会准确指向出错的元素,这让您很难理解它在提示什么。

关于c - 警告 : initializer element is not computable at load time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28408711/

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