NO

Author Topic: Redeclaration, error #2120  (Read 3879 times)

GuF

  • Guest
Redeclaration, error #2120
« on: May 19, 2006, 08:39:10 PM »
Pelles C 4.0 doesn't compile this (redeclaration, error #2120):

Code: [Select]

int a() {
void b();
}

static void b() {
}


Thanx, if you could have a look on this!

Offline DMac

  • Member
  • *
  • Posts: 272
Redeclaration, error #2120
« Reply #1 on: May 19, 2006, 08:54:26 PM »
You have reversed the proper order try this:

static void b() {
}

int a() {
   void b();
}

or use a prototype for void b()

also you do not need to prepend keyword "void" to b when you are calling it from within a.

int a() {
   b();
}

-DMac
No one cares how much you know,
until they know how much you care.

Synfire

  • Guest
Redeclaration, error #2120
« Reply #2 on: May 19, 2006, 09:02:51 PM »
Code: [Select]

int a() {
   void b();
}

static void b() {
}


That's because you are prototyping the b() function twice. If you wish to typecast, you must encapsulate the cast in parethesis like so

Code: [Select]

#include <stdio.h>

static void b ( void );
int a ( void );

int a() {
   (void) b();
   return ( 0 );
}

static void b() {
}

int main () { return ( a ( ) ); }


To note another possible error, in you code you define a() as an int but don't return anything. None the less, the code above compiles without a hitch as a console app.

Regards,
Bryant Keller