WARNING: While resolving call to function 'help' arguments were dropped!
如果我使用gcc -O3 codice -o out/codice
进行编译,我会收到这个令人讨厌的警告。它完成了编译,所以我只是想知道为什么会这样。
我在安装xcode 4.3的狮子上安装了mac。它使用的编译器是i686-apple-darwin11-llvm-gcc-4.2
请注意,如果我将-O3
切换为-O2 / -O1 / -O,则会继续发出相同的警告
代码如下....
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <math.h>
void help();
char *codice_encrypt(char *in);
char *codice_decrypt(char *in);
void sigint_handler(int signal) {
exit(2);
}
int main (int argc, char **argv) {
if (argc != 3) {
help();
}
signal(SIGINT, sigint_handler);
char *ret, *status;
int tmpret;
if (strcmp(argv[1], "e") == 0 || strcmp(argv[1], "encrypt") == 0) {
status = "Encrypting...\n";
tmpret = write(STDOUT_FILENO, status, strlen((const char *)status));
ret = codice_encrypt(argv[2]);
} else if (strcmp(argv[1], "d") == 0 || strcmp(argv[1], "decrypt") == 0) {
status = "Decrypting...\n";
tmpret = write(STDOUT_FILENO, status, strlen((const char *)status));
ret = codice_decrypt(argv[2]);
} else {
status = "Could not understand command line arguments O.o\n";
tmpret = write(STDOUT_FILENO, status, strlen((const char *)status));
help(STDOUT_FILENO);
}
status = "Success!\nRetval:\n\n";
tmpret = write(STDOUT_FILENO, status, strlen((const char *)status));
tmpret = write(STDOUT_FILENO, ret, strlen((const char *)ret));
tmpret = write(STDOUT_FILENO, "\n\n", 2);
return 0;
}
void help() {
int tmpret;
const char *logo = "\n\n\t\tooooooo__oo______________________\n"
"\t\t_____oo______oo_oo_oo__oo_oo_oo__\n"
"\t\t____oo___oo__ooo_oo__o_ooo_oo__o_\n"
"\t\t___o_____oo__oo__oo__o_oo__oo__o_\n"
"\t\t_oo______oo__oo__oo__o_oo__oo__o_\n"
"\t\tooooooo_oooo_oo______o_oo______o_\n"
"\t\t_________________________________\n\n\n";
tmpret = write(STDOUT_FILENO, logo, strlen(logo));
const char *help = "Help\n"
"Is\n"
"Still\n"
"Being\n"
"Written :)\n\n";
tmpret = write(STDOUT_FILENO, help, strlen(help));
exit(1);
}
char *codice_encrypt(char *in) {
unsigned int i;
char ya = 0x55;
write(STDOUT_FILENO, "0x", 2);
char itret[50];
sprintf(itret,"%#hhx",ya);
write(STDOUT_FILENO, itret, strlen(itret));
write(STDOUT_FILENO, "\n", 1);
ya = ya & 0x0F;
ya = ya >> 1;
sprintf(itret,"%#hhx",ya);
write(STDOUT_FILENO, itret, strlen(itret));
write(STDOUT_FILENO, "\n", 1);
ya = 0x55;
ya = ya & 0xF0;
ya = ya << 1;
sprintf(itret,"%#hhx",ya);
write(STDOUT_FILENO, itret, strlen(itret));
write(STDOUT_FILENO, "\n", 1);
return in;
}
char *codice_decrypt(char *in) {
return in;
}
谢谢!
答案 0 :(得分:1)
这里help()有可变数量的参数(我假设我们正在谈论C代码)。但是,没有传递任何参数,也没有读取参数。其中一个优化通过实现了这一点并发出了这样的警告。将help()定义为help(void)将解决问题。