9

I'm having trouble compiling some C code. 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

6
  • 3
    Show the declaration of sp_session_login().
    – Kerrek SB
    Sep 23, 2011 at 21:10
  • You have bool defined in C? Not good practice. Sep 23, 2011 at 21:11
  • If you use clang, you might get better error messages, too.
    – Carl Norum
    Sep 23, 2011 at 21:11
  • 1
    A login function that has no error return, that's weird. Well, very understandable mistake. Sep 23, 2011 at 21:14
  • 4
    @James: bool is just fine in C99 if you include <stdbool.h>.
    – Maister
    Sep 23, 2011 at 21:14

5 Answers 5

8

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.

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;
}
1
8

It usually means you assign the return of a void function to something, which is of course an error.

In your case, I guess the sp_session_login function is a void one, hence the error.

2

I'm going to guess that sp_session_login is declared as returning void and not sp_error and there is some alternative way of determining whether it succeeded.

2

It doesn't look like sp_session_login actually 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.

-1

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.

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);
}
1
  • 2
    This does not answer the question. All functions should be declared before use (C99 requires this, and it's good practice in C90). The OP already declared sp_session_login by #includeing the appropriate header; that's how the compiler knows it's a void function. The problem is that the OP attempted to assign the nonexistent result of a void function to a variable; your answer doesn't address the actual problem. Oct 26, 2013 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.