Re: const oddity in decorated names
On Wed, 21 Feb 2007 06:35:34 -0800, J Levin <J
Levin@discussions.microsoft.com> wrote:
If I declare the functions
void foo(int bar[])
void bar(int * bar)
then I expect them to behave the same way - and indeed they do in most
cases. I have give these functions these (admittedly meeningless)
implementation:
__declspec(dllexport) void f(int x[]) {}
__declspec(dllexport) void g(int *y) {}
The program compiles. If I look at the decorated names of the exported names
in the dll they aren't the same though. foo gets a decorated names that
indicates that it was declared as
void foo(int * const bar).
But since the program above compiled that is obviously not the case.
It appears that while the compiler realizes that x is int*, it's hanging on
to the belief that it is partly an array since it's declared that way, and
since array names cannot be assigned to, it's making x const for decoration
purposes. The typeid().name() does the same thing in VC8, with or without
the __declspec.
I'll have admit that the difference between "int *" and "int * const" in a
function argument is irrelevant to the caller of the function, but is there a
reason for this oddity, or is this just a mistake?
Mistake. What happens if you try this in a DLL client:
__declspec(dllimport) void f(int* x);
__declspec(dllimport) void g(int y[]);
Can you call f and g? You should be able to. If you can, it would seem to
be a pretty innocuous mistake, except that it also affects typeid
(including type_info::before), which could conceivably cause problems if
you were doing something that required ordering or identifying functions
types. I'm unable to imagine a use for this, but you might want to bug it
anyway here:
http://connect.microsoft.com/feedback/default.aspx?SiteID=210
--
Doug Harrison
Visual C++ MVP