1

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;
}
ChThy
  • 221
  • 1
  • 4
  • 12
  • Change the order of the function definitions. – Some programmer dude Sep 04 '14 at 11:39
  • 1
    What "hi-tech-c" is? Just curious... – Adriano Repetti Sep 04 '14 at 11:39
  • @AdrianoRepetti *Hi-TECH Software* is a company that makes C compilers targeting embedded systems, amongst other things. They have been around a long time (I remember on my ZX Spectrum, seeing Hitech C advertised in a magazine) – M.M Sep 04 '14 at 11:44
  • @joachim: do you mean I have to place the function "integer_reverse" above the function "mode_single_right"? – ChThy Sep 04 '14 at 11:44
  • Sadly I have used a version of Hitech C to code for a device with a Z80 in more modern times; and the less said about that the better. – M.M Sep 04 '14 at 11:45
  • @maikel either that or place a function prototype as my answer describes – M.M Sep 04 '14 at 11:45
  • @maikel Yes that's right. In C you need to declare things before you use them. By placing the `integer_reverse` function before you you call it, you will have it declared before you use it. – Some programmer dude Sep 04 '14 at 11:46
  • @MattMcNabb thank you! You may also update that tag for next ignorant one after me! – Adriano Repetti Sep 04 '14 at 11:53

2 Answers2

5

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.

M.M
  • 138,810
  • 21
  • 208
  • 365
0

Either add a forward declaration like

unsigned int integer_reverse (unsigned int input_br);

or

define the function before calling [using] it.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
  • if I choose to define the function, can I leave the "unsigned" at the fuction itself? – ChThy Sep 04 '14 at 11:42
  • @maikel why you want to do that? – Sourav Ghosh Sep 04 '14 at 11:43
  • I have no idea.. just asking if the integer would be an unsigned integer in case that the funstion is defined at the beginning of the program – ChThy Sep 04 '14 at 11:47
  • @maikel seriously?? :-) if you are not specifying exactly what you *want*, then be ready for the surprises the compiler can present to you. JA, mention exactly what you want/need. – Sourav Ghosh Sep 04 '14 at 11:49
  • @maikel Cheers man! Nothing to be sorry. *One who asks is a fool for 5 minutes, one who does not is a fool for lifetime.* :-) HTH – Sourav Ghosh Sep 04 '14 at 11:59