C语言 GCC C 编译错误,没有忽略无效值,因为它应该是
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7534880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GCC C compile error, void value not ignored as it ought to be
提问by Endre Hovde
I'm having trouble compiling some C code. When I compile, I'l get this error:
我在编译一些 C 代码时遇到问题。当我编译时,我会收到这个错误:
player.c: In function ‘login':
player.c:54:17: error: void value not ignored as it ought to be
This is the code for the error:
这是错误的代码:
static bool login(const char *username, const char *password) {
sp_error err = sp_session_login(g_sess, username, password, remember_me);
printf("Signing in...\n");
if (SP_ERROR_OK != err) {
printf("Could not signin\n");
return 0;
}
return 1;
}
Any way to bypass this kind of error?
Thanks
有什么办法可以绕过这种错误?
谢谢
Edit:All sp_ functions are from libspotify
编辑:所有 sp_ 函数都来自 libspotify
采纳答案by ldav1s
Where is the error line exactly?
错误行究竟在哪里?
Without further information, I'm guessing it's here:
没有更多信息,我猜它在这里:
sp_error err = sp_session_login(g_sess, username, password, remember_me);
I guess sp_session_login is returning the void.
我猜 sp_session_login 正在返回无效。
Try:
尝试:
static bool login(const char *username, const char *password) {
sp_session_login(g_sess, username, password, remember_me);
printf("Signing in...\n");
return 1;
}
回答by Macmade
It usually means you assign the return of a void function to something, which is of course an error.
这通常意味着您将 void 函数的返回值分配给某物,这当然是错误的。
In your case, I guess the sp_session_loginfunction is a void one, hence the error.
在你的情况下,我猜这个sp_session_login函数是一个空函数,因此是错误的。
回答by moonshadow
I'm going to guess that sp_session_loginis declared as returning voidand not sp_errorand there is some alternative way of determining whether it succeeded.
我猜这sp_session_login被声明为返回void而不是,sp_error并且有一些替代方法可以确定它是否成功。
回答by Ismail Badawi
It doesn't look like sp_session_loginactually returns anything. In particular, it doesn't return an sp_error, so there's no way this could work. You can't really bypass it.
看起来sp_session_login实际上并没有返回任何东西。特别是,它不返回sp_error,所以这不可能工作。你真的无法绕过它。
回答by AlanVncs
You must declare void functions before use them. Try to put them before the main function or before their calls. There's one more action you can do: You can tell the compiler that you will use void functions.
您必须在使用它们之前声明 void 函数。尝试将它们放在主函数之前或调用之前。您还可以执行一项操作:您可以告诉编译器您将使用 void 函数。
For exemplo, there are two ways to make the same thing:
例如,有两种方法可以制作相同的东西:
#include <stdio.h>
void showMsg(msg){
printf("%s", msg);
}
int main(){
showMsg("Learn c is easy!!!");
return 0;
}
...and the other way:
...另一种方式:
#include <stdio.h>
void showMsg(msg); //Here, you told the compiller that you will use the void function showMsg.
int main(){
showMsg("Learn c is easy!!!");
return 0;
}
void showMsg(msg){
printf("%s", msg);
}

