ChThy
ChThy

Reputation: 251

conflicting declarations for variable, type redeclared

I have these errors and a warning... I'm quite new to programming and I have no idea what it means. Can you guys take a look at this and tell me what I'm doing wrong?

Thanks in advance

Errors and warning:

Looplicht v2.0.c:226: warning: (361) function declared implicit int
Looplicht v2.0.c:237: error: (984) type redeclared
Looplicht v2.0.c:237: error: (1098) conflicting declarations for variable "integer_reverse" (Looplicht v2.0.c:237)

code with errors (I have placed the linenumbers of the errors in the description):

void mode_single_right() {

output_integer = 0x0001;        //start right

    for (unsigned char i = 0; i < number_of_outputs; i++) {
        if (jump) {
            jump = 0;
            
            output_integer = integer_reverse(output_integer);       //line 226
            switch_outputs(output_integer);                         
            output_integer = (output_integer << 1);                 
        } else {
            i--;
        }
    }


}

unsigned int integer_reverse (unsigned int input_br) {          //line 237

unsigned int output_br = 0;
bit bit_in_reverse = 0;

for (unsigned char ibr = 0; ibr < 16; ++ibr) {

    bit_in_reverse = input_br & 0x01;
    output_br |= bit_in_reverse;
    input_br >>= 1;
    output_br <<= 1;
}
return output_br;
}

Upvotes: 1

Views: 13367

Answers (2)

M.M
M.M

Reputation: 141628

You should declare a function before calling it. At some point before line 226 (preferably outside of any function), include a prototype:

unsigned int integer_reverse( unsigned int input_br );

If you call a function which has not been declared, in C89, the compiler assumes that the declaration was:

int integer_reverse();

Then it encounters your function header (which is in prototype format, so it counts as a prototype) and the compiler detects that this prototype is not compatible with your original implicit declaration.

Upvotes: 6

Sourav Ghosh
Sourav Ghosh

Reputation: 134356

Either add a forward declaration like

unsigned int integer_reverse (unsigned int input_br);

or

define the function before calling [using] it.

Upvotes: 0

Related Questions