[英]GCC C compile error, void value not ignored as it ought to be
I'm having trouble compiling some C code. 我在编译一些C代码时遇到了麻烦。 When I compile, I'l get this error:
当我编译时,我得到这个错误:
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
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_login
function is a void one, hence the error. 在你的情况下,我猜
sp_session_login
函数是一个空的函数,因此错误。
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;
}
我猜测sp_session_login
被声明为返回void
而不是sp_error
并且有一些替代方法来确定它是否成功。
It doesn't look like sp_session_login
actually returns anything. 它看起来不像
sp_session_login
实际返回任何东西。 In particular, it doesn't return an sp_error
, so there's no way this could work. 特别是,它不会返回
sp_error
,因此无法使用它。 You can't really bypass it. 你无法真正绕过它。
You must declare void functions before use them. 您必须在使用之前声明void函数。 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函数。
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.