简体   繁体   English

GCC C编译错误,无法忽略void值,因为它应该是

[英]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.

相关问题 MINGW编译错误:无法忽略void值,因为它应该是 - MINGW compile error: void value not ignored as it ought to be 错误:没有忽略空值,因为它应该在 C 编程中 - Error: Void value not ignored as it ought to be in C programming 错误:C编程中应忽略的空值 - error: Void Value not ignored as it ought to be, C programming C编程中的错误“无效值不应该被忽略” - Error “void value not ignored as it ought to be” in C programming 返回一个int的函数上的C“无效值不应该被忽略”错误 - C “void value not ignored as it ought to be” error on a function that returns an int 错误:无效值不应该被忽略-C / GTK + - error: void value not ignored as it ought to be - C/GTK+ 在C中获得“无效值不应该被忽略” - getting “void value not ignored as it ought to be” in C 警告:取消引用“void *”指针[默认启用]和错误:没有忽略无效值,因为它应该有助于c - warning: dereferencing ‘void *’ pointer [enabled by default] and error: void value not ignored as it ought to be help c 三元运算符用法错误,“ ERROR:应忽略的无效值” - Ternary operator usage error, “ERROR:void value not ignored as it ought to be” 构建驱动程序会产生“错误:没有忽略无效值,因为它应该是” - Building drivers yields `error: void value not ignored as it ought to be`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM