Error: identifier something(char) redeclared as void something(char)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error: identifier something(char) redeclared as void something(char)

3,165 Views
FridgeFreezer
Senior Contributor I

As part of a project to migrate from an MCORE project in CW5 to MCF5225x in CW 7.1.1a, I have loaded (a duplicate of) the example project (MCF52259EVB/example.mcf) in CW 7.1 (the version that came with the EVB) and then pasted the main source & header files from the old CW5 project into the new project - the plan being to hit "build" and see all the stuff that breaks, then work through it tweaking old code to point to the new CPU/EVboard definitions to hopefully end up with a working demo.

 

Anyway, one thbing I didn't expect was for CW to throw errors for what seems like every single function declaration.

 

For example:

 

In buffers.c:

void buffer_init(struct buffer_struct *buffer)
{
...
}

 


 

In buffers.h:

void buffer_init(struct buffer_struct *buffer);

 

The error messages take the form:

 

Error: identifier 'buffer_init(struct buffer_struct *)' redeclared as 'void void buffer_init(struct buffer_struct *)' in buffers.c

 

And

 

 

Error: identifier 'buffer_init(struct buffer_struct *)' was originally declared as 'void void buffer_init(struct buffer_struct *)' in buffers.h

 

The compiler also throws errors like this for some code, claiming illegal conversion between identical types:

 

Error: Illegal implicit conversion from 'struct buffer_struct *' to 'struct buffer_struct *'

 

 I don't know if this lot is due to an incorrect compiler setting or a different C standard from the old version of CW to the new one. Can anyone shed any light?
Labels (1)
0 Kudos
5 Replies

696 Views
CrasyCat
Specialist III

Hello

 

Can you try to preprocess the source file buffers.c and look how the definition and declaration of the function buffer_init looks like there.

 

There might be some unexpected macro expansion taking place here.

 

If you so not find it yourself, I would recommend you to submit a service request for that.

Click here to submit a service request.

Make sure to attach a reproducible project and installed product information to the service request.
To generate the required information:
- Start CodeWarrior
- Open the project
- Select "Help" -> "Pack and Go" and follow instructions on the screen.

Attach the generated .zip file to the SR.

 

CrasyCat

0 Kudos

696 Views
FridgeFreezer
Senior Contributor I

Both files preprocess OK, as I said these were cut-and-paste from an existing fully working project. I was expecting some errors due to the changed processor / board defines, but this throws an error for every function definition in the whole project :smileysurprised: which, for a fairly small project, means 450+ errors and even more warnings.

0 Kudos

696 Views
CompilerGuru
NXP Employee
NXP Employee

For this code:

 

void fun(struct A*);
void fun(struct A* p) {
}

 


I get with the CF compiler in CW for MCU 6.3 the following warnings:

 

 

Warning : types that are declared in parameter lists ('A') go out of scope at the end of the function declaration/definition,this is probably not what you want (maybe use a forward declaration?)main.c line 1   void fun(struct A*);  Warning : types that are declared in parameter lists ('A') go out of scope at the end of the function declaration/definition,this is probably not what you want (maybe use a forward declaration?)main.c line 2   void fun(struct A* p) {  Error   : identifier 'fun(struct A *)' redeclared as '__regabi void (struct A *)'main.c line 2   void fun(struct A* p) {  Error   : identifier 'fun(struct A *)' was originally declared as '__regabi void (struct A *)'main.c line 1   void fun(struct A*);  

 

Or in other words, the struct tag was first seen in a parameter declaration. As this is a local scope,

the compiler does not treat it as the same type as in the function definition even if it does have the same tag name.

In order to fix this, just declare the tag before using it in the declaration.

E.g.

 

 

struct A;void fun(struct A*);void fun(struct A* p) {}

 

Daniel

 

BTW: The title of this post is a bit misleading as this does not happen for basic types like char's only for user defined tags.

 

 

0 Kudos

696 Views
FridgeFreezer
Senior Contributor I

Daniel,

I think I understand what you mean, but I don't understand why this code worked once but doesn't now.

 

If I have, in buffers.h:

struct buffer_struct{char somethingchar datachar blah};

And the function definiton:

void buffer_init(struct buffer_struct *buffer);
 

Then in buffers.c:

#include "buffers.h"

void buffer_init(struct buffer_struct *buffer)
{
...
}

I'm not sure I understand what the problem is. The same structs are used throughout the code so are each defined in one place (in this case buffers.h). I've even checked the link order for the original project and made sure things are done in the same order.

 

If it's any help, the original project is in CodeWarrior 4.1 (for M.Core), which was how the project arrived with us, and it compiles and runs with no errors/warnings.

0 Kudos

696 Views
CompilerGuru
NXP Employee
NXP Employee

Is the struct defined in buffer.h before the buffer_init declaration?

Is this a C or a C++ project?

The link order does not matter for compile time warnings and errors. Instead have a look at the preprocessor file. Check the order in which the buffer_struct tag name shows up, is the struct type definition really the first occurence? Make sure to have the struct tag defined in the global scope (in the proper namespace if C++). One way to simplify it is to safe the preprocessor output as C file and then to start cut things out as long as the warning shows up. In the end a reproducible code snippet would help us to really figure out what the problem is.

 

Daniel

 

 

 

0 Kudos