|
0 registered members (),
3,614
guests, and 4
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
overloaded functions and pointer-conversion query
#338926
08/22/10 19:34
08/22/10 19:34
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Hi all.
Question 1> I believe the lite-c does some form of auto-object-to-pointer conversion when dealing with NON-overloaded functions. ie. func(my.x); --> void func(VECTOR* pos) conversion. Can someone please explain the 'steps' this conversion follows in deciding whether to convert, and what to convert to, etc.
Question 2> I believe this auto-conversion DOESNT apply when dealing with OVERLOADED functions. Is it "theoretically" possible for the engine to be upgraded to auto-convert overloaded functions too? If not, why not?
Thanks guys.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: overloaded functions and pointer-conversion query
[Re: EvilSOB]
#338930
08/22/10 19:52
08/22/10 19:52
|
Joined: Feb 2006
Posts: 1,011 Germany
pegamode
Serious User
|
Serious User
Joined: Feb 2006
Posts: 1,011
Germany
|
As far as I know auto-conversion should apply also with overloaded functions, but there was a long time bug using strings in overloaded functions, but it was fixed in 7.83.2: Overloaded functions weren't found by the compiler when the function prototype expected a STRING* argument, but was called with a char* or char[] constant (all A7 versions; fixed in 7.83.6). Workaround: Define the overloaded prototype with a char* parameter.
|
|
|
Re: overloaded functions and pointer-conversion query
[Re: pegamode]
#338932
08/22/10 20:06
08/22/10 20:06
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
When calling overloaded functions, make sure that argument types exactly match one of the defined functions. The automatic type conversion and pointer detection of the lite-C compiler does not happen here. That means you must really use the C++ & operator for pointers. And for me it is mostly the VECTOR* that give me problems. There are so many ways to call it... example: this code works fine...
void funcA(VECTOR* pos)
{ ... }
void funcB(VECTOR* pos, int height)
{ ... }
action play()
{
funcA(my.x);
funcB(my.x, 1);
}
But this will fail on compile
void func(VECTOR* pos)
{ ... }
void func(VECTOR* pos, int height)
{ ... }
action play()
{
func(my.x);
func(my.x, 1);
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: overloaded functions and pointer-conversion query
[Re: Lukas]
#338935
08/22/10 20:21
08/22/10 20:21
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Yeah Lukas, that will "work"... But with UN-overloaded it works fine without re-casting.
Thats what Im asking about, the AUTO conversions...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: overloaded functions and pointer-conversion query
[Re: jcl]
#340642
09/06/10 10:02
09/06/10 10:02
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
OK, thanks. I suspected as much.
So overloaded functions cant do what I wnt in "this" instance.
Thanks anyway...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|