Click here to Skip to main content
15,887,249 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C2084 FUNCTION ALREADY HAS A BODY Pin
Albert Holguin18-Dec-16 16:28
professionalAlbert Holguin18-Dec-16 16:28 
GeneralRe: C2084 FUNCTION ALREADY HAS A BODY Pin
ForNow18-Dec-16 16:34
ForNow18-Dec-16 16:34 
GeneralRe: C2084 FUNCTION ALREADY HAS A BODY Pin
Albert Holguin18-Dec-16 17:02
professionalAlbert Holguin18-Dec-16 17:02 
GeneralRe: C2084 FUNCTION ALREADY HAS A BODY Pin
leon de boer18-Dec-16 16:31
leon de boer18-Dec-16 16:31 
AnswerRe: C2084 FUNCTION ALREADY HAS A BODY Pin
Richard MacCutchan18-Dec-16 21:48
mveRichard MacCutchan18-Dec-16 21:48 
GeneralRe: C2084 FUNCTION ALREADY HAS A BODY Pin
Peter_in_278018-Dec-16 23:09
professionalPeter_in_278018-Dec-16 23:09 
GeneralRe: C2084 FUNCTION ALREADY HAS A BODY Pin
Richard MacCutchan19-Dec-16 5:38
mveRichard MacCutchan19-Dec-16 5:38 
GeneralRe: C2084 FUNCTION ALREADY HAS A BODY Pin
leon de boer19-Dec-16 19:03
leon de boer19-Dec-16 19:03 
It won't be commented out nor does it need to be. I take it he is just using the commenting out to show whats there.

Assuming it uncommented it's an extern (which is nothing more than a forward prototype) with a macro calling the extern. That won't create any problem at all as there is clearly no function body provided in hmacros.h by doing that and it will simply defer to the extern body provided with one big proviso that the prototype matches the external body declaration.

I am still backing that BYTE gets defined differently (probably inside hmacros.h) and so the prototype doesn't match the body. We know BYTE must be defined prior to CPU.C using it and CPU.C then includes hamacros.h. I am betting hmacros.h defines BYTE as well (probably one is as a char and one as unsigned char).

Given that the compiler is seeing no macro redefinition etc it's clear one will be #define BYTE ... and the other typedef so BYTE has two valid but different definitions which don't on their own clash.

Here try it
typedef unsigned char BYTE;
void hex_to_ascii(BYTE *ipx, char *str, int num);  // forward declaration

#define BYTE char
void hex_to_ascii(BYTE *ipx, char *str, int num) {

};

That is illegal in C especially if one is declared extern, the header and the body don't match because they are using different versions of BYTE. In C++ it would overload and then tell you one of your overloads hasn't got a body definition. Remove the macro and it will compile correctly because the forward declaration and body match then.

It's dead easy to do and one of the normal problems of merging multiple libraries who like to make there own definitions.
In vino veritas


modified 20-Dec-16 1:56am.

GeneralRe: C2084 FUNCTION ALREADY HAS A BODY Pin
Albert Holguin21-Dec-16 10:41
professionalAlbert Holguin21-Dec-16 10:41 
GeneralRe: C2084 FUNCTION ALREADY HAS A BODY Pin
leon de boer23-Dec-16 6:26
leon de boer23-Dec-16 6:26 
GeneralRe: C2084 FUNCTION ALREADY HAS A BODY Pin
Albert Holguin23-Dec-16 7:25
professionalAlbert Holguin23-Dec-16 7:25 
GeneralRe: C2084 FUNCTION ALREADY HAS A BODY Pin
leon de boer23-Dec-16 8:37
leon de boer23-Dec-16 8:37 
QuestionMFC code to move a train in two directions Pin
Member 1289526213-Dec-16 19:17
Member 1289526213-Dec-16 19:17 
AnswerRe: MFC code to move a train in two directions Pin
CPallini13-Dec-16 21:22
mveCPallini13-Dec-16 21:22 
AnswerRe: MFC code to move a train in two directions Pin
jeron114-Dec-16 4:40
jeron114-Dec-16 4:40 
GeneralRe: MFC code to move a train in two directions Pin
Richard MacCutchan14-Dec-16 5:08
mveRichard MacCutchan14-Dec-16 5:08 
GeneralRe: MFC code to move a train in two directions Pin
jeron114-Dec-16 5:11
jeron114-Dec-16 5:11 
SuggestionRe: MFC code to move a train in two directions Pin
David Crow14-Dec-16 5:36
David Crow14-Dec-16 5:36 
AnswerRe: MFC code to move a train in two directions Pin
Chris Losinger14-Dec-16 11:00
professionalChris Losinger14-Dec-16 11:00 
AnswerRe: MFC code to move a train in two directions Pin
Gerry Schmitz14-Dec-16 12:21
mveGerry Schmitz14-Dec-16 12:21 
AnswerRe: MFC code to move a train in two directions Pin
Patrice T14-Dec-16 12:45
mvePatrice T14-Dec-16 12:45 
AnswerRe: MFC code to move a train in two directions Pin
Munchies_Matt30-Dec-16 7:35
Munchies_Matt30-Dec-16 7:35 
QuestionTiny Encryption Algorithm Pin
Rhonnn12-Dec-16 20:42
Rhonnn12-Dec-16 20:42 
AnswerRe: Tiny Encryption Algorithm Pin
Jochen Arndt12-Dec-16 20:55
professionalJochen Arndt12-Dec-16 20:55 
AnswerRe: Tiny Encryption Algorithm Pin
Patrice T14-Dec-16 12:39
mvePatrice T14-Dec-16 12:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.