Jenna K
Jenna K

Reputation: 21

C "void value not ignored as it ought to be" error on a function that returns an int

I have the following code and am getting

"error: void value not ignored as it ought to be

int ab = findActiveBlock();"

I would understand this error if findActiveBlock was set to void but it is returning an int? Please help

void updateActiveBlock() {

    int ab = findActiveBlock();
    //code using ab//
}

int findActiveBlock() {
    for (int i = 0; i < BLOCKCOUNT; i++) {
        if(blocks[i].active) {
            return i;
        }
    }
    return 1;
}

additional info: this is C, "blocks[]" is an array of structs.

Upvotes: 1

Views: 707

Answers (2)

AnT stands with Russia
AnT stands with Russia

Reputation: 320471

I would make a wild guess that your findActiveBlock is actually pre-declared somewhere above as a void-returning function. You simply forgot to update that declaration to make it match the definition.

P.S. As an additional side note: () parameter lists is an obsolescent feature in C. For functions that have no parameters, prefer to use (void) in their declarations.

Upvotes: 4

steve
steve

Reputation: 1

Just a stab in the dark, but is *.active a function? If so it would need parentheses.

 int findActiveBlock() {
    for (int i = 0; i < BLOCKCOUNT; i++) {
        if(blocks[i].active()) {   //added parentheses to active
            return i;
        }
    }
    return 1;
}

Upvotes: -2

Related Questions