More on decoration
Why is the decoration method for C++ names Microsoft proprietary? When I try to compile the files below, the function MyFPXInit is decorated as ?MyFPXInit@@ZA?EW4FPXStatus@@PEKPEDJ@Z in the file a1.cpp but is decorated as ?MyFPXInit@@ZA?EW4FPXStatus@@PEKPEDK@Z in file a2.cpp instead and results in a link error. Why are the names decorated differently? What is the difference between a "J" and a "K" in the decorated name? I am using Microsoft Visual C++ 1.52. I use the command line cl /c /AL /Fc and am getting the decorated names from the .cod file.
File: A1.H
extern FPXStatus MyFPXInit (unsigned long *memSizeInBytes,
char *requiredVersionName,
unsigned long requiredVersionNumber);
File: A1.CPP
FPXStatus MyFPXInit (unsigned long *memSizeInBytes,
char *requiredVersionName,
long requiredVersionNumber)
{
return(FPX_OK);
}
File: A2.CPP
#include "a1.h"
void main()
{
unsigned long memoryLimit = 2000000L;
MyFPXInit(&memoryLimit, 0, 0);
}
Thanks,
David Cook
What, you think Dr. GUI is an interior decorator now? Puh-leeze! Oh, it's another programming question. The good doctor can deal with this.
First, note that there is no standard for C++ name decoration. It sometimes even varies between versions of the same compiler. So everybody's name decoration is proprietary (more accurately, it's unique), not just Microsoft's. The reason that the linker is complaining is that the function being defined is:
FPXStatus MyFPXInit(unsigned long, char, long);
And the one being called is, according to the header:
FPXStatus MyFPXInit(unsigned long, char, unsigned long);
In other words, when you defined the function with a parameter type different from the header, you defined an entirely new overload. And you provided no definition for the declaration of the other functionthus, the linker error.
Then, by deduction, the answer to your question is that the difference between a "J" and a "K" is "unsigned."
The Microsoft Knowledge Base (KB) has an article, "C++ Name Decoration, Why It's Used; How to Get Decorated Names" (Article ID: Q126845), which should answer your other question.
Although unnecessary in this case, if you wanted to undecorate the symbol name you have a couple of options. You could use the Browser Toolkit; it has a function that will undecorate the symbol name. If you were in Win32, you could use the UnDecorateSymbolName API. Since you are in 16-bit land, you should get the .bsc library. The details where this can be obtained are in the KB article "Browser Toolkits for Microsoft Visual C++" (Article ID: Q153393).