We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello, I'm using the C51 compiler for a C8051F043 target. I'm allocating a variable array with the statement: unsigned char xdata gbuf[2048]; When I compile, I get an Error C231, redefinition of gbuf. The problem is, it's not defined elsewhere in code. To make sure I commented out this statement, and sure enough, I get a linker error because it can't find gbuf. Has someone got an idea of what my problem may be? Thanks, Brian Warren
Thanks for the idea. That lead me to it. There was an included file with the variable declared as extern. Thanks for the help!
The existence of that header files shouldn't have caused any problems. If it did, that means not only was there a declaration of this variable in your header, but that it was conflicting with the definition you cited. Having "extern" declarations in header files is actually strongly recommended practice. But you still have to do it right.
"The existence of that header files shouldn't have caused any problems." Oh yes it should! "If it did, that means not only was there a declaration of this variable in your header, but that it was conflicting with the definition you cited." Exactly: and the message you get will complain about a re-definition - which was precisely the issue reported in the original post.
Oh yes it should! I don't think so. Not with the variable declared "extern", like the OP said it was. It's perfectly allowed to declare the same variable 'extern' a thousand times, as long as you don't also give it an initializer. Which brings it back to actual differences between the extern declaration in the header, and the definition in the source which the OP showed us.
OK, if the only difference were the 'extern' keyword - I agree. But, like I said in my original reply, if the header has a different declaration - that should cause the described symptoms.