Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: Jettah on December 08, 2004, 04:41:57 PM

Title: Error on DoMethod()
Post by: Jettah on December 08, 2004, 04:41:57 PM
Hi,

While designing a simple program I encountered an error and a warning when using DoMethod().

Here is a part of the offending source:

struct Window *Win = NULL;
if (Win = (struct Window *)DoMethod(&WinObj, WM_OPEN, NULL))
{
//anything usefull here
}

The warning is: cast does not match function type
The error sounds: Win has an incomplete type

Can anyone shed some light on this matter?

Regards,

Jettah
Title: Re: Error on DoMethod()
Post by: Piru on December 08, 2004, 04:55:41 PM
Quote
if Win = (struct Window *)DoMethod(&WinObj, WM_OPEN, NULL))

Missing parenthesis.

if (moo)
not
if moo
Title: Re: Error on DoMethod()
Post by: Jettah on December 08, 2004, 05:02:36 PM
@Piru

Stands corrected. My keyboard is a bit sticky on that particular key.

The source code however does contain that parenthesis.

Thanks anyway

Jettah
Title: Re: Error on DoMethod()
Post by: DaveP on December 08, 2004, 05:32:31 PM
Sounds like an include problem. Gcc and similar compilers report "incomplete type" for structures that are used but not declared.

In this case win is not defined, because the "struct Window" structure has not been declared in entirity. Check you have all the intuition includes required in order to use it.

Title: Re: Error on DoMethod()
Post by: Jettah on December 08, 2004, 05:41:15 PM
@DaveP

"Check you have all the intuition includes required in order to use it."

struct Window is defined in intuition/intuition.h, which is included.

Thanks

Jettah

Title: Re: Error on DoMethod()
Post by: Thomas on December 09, 2004, 07:00:11 AM

What about DoMethod ? Did you include proto/intuition.h and are you compiling with -D__USE_INLINES ?

And what about WinObj ? Usually I'd declare it as Object *WinObj. As such it already is a pointer to an object and you give a pointer to the pointer to DoMethod. You should rather give the pointer itself.

Bye,
Thomas
Title: Re: Error on DoMethod()
Post by: nicomen on December 09, 2004, 07:07:30 AM
Which Amiga platform and version are you using?

What does the same line look after compiling with -E, ie. just running the preprocessor over it. Does DoMethod get delcared somewhere?

If OS4 and using __USE_INLINE__ add -DDoMethod=IDoMethod to GCC. if not using __USE_INLINE__ try adding -DDoMethod="IIntuition->IDoMethod"

Title: Re: Error on DoMethod()
Post by: Jettah on December 09, 2004, 08:31:19 AM
@Thomas


Up to now I have this piece of source code (relevant part only):

{                                                 // level 0
Object *WinObj = NULL;
if (WinObj = )
{                                                 // level 1
struct Window *Win = NULL;
if (Win = struct Window *)DoMethod(WinObj, WM_OPEN, NULL))
{                                                 // level 2
// Try to do the usefull stuff here...

DoMethod(WInObj, WM_CLOSE, NULL);
Win    = NULL;
WinSig = 0L;
}                                                 // level 2
DisposeObject((Object *)WinObj);
WinObj = NULL;
}                                                 // level 1
}                                                 // level 0

I now get the WARNING: cast does not match funktion type
intuition protos are included explicitly:
#include

Sytem used: A1200 OS3.9 StormC4 Gcc

Why, oh why, do I get a warning about a cast? IMHO I'm doing it the correct way, but I can be wrong of course.

Thanks,

Jettah
Title: Re: Error on DoMethod()
Post by: Thomas on December 09, 2004, 09:33:36 AM

nicomen is correct. I remembered that DoMethod has been moved from amiga.lib to intuition.library with OS4.0, but I missed that it was also renamed to IDoMethod.

On OS3.9 you have to include clib/alib_protos.h for the DoMethod prototype.

Sometimes you should look into the include files. If you don't find DoMethod in intuition_protos.h, you know that you missed another include file.

Bye,
Thomas
Title: Re: Error on DoMethod()
Post by: Jettah on December 09, 2004, 09:54:47 AM
@Thomas

Quote
On OS3.9 you have to include clib/alib_protos.h for the DoMethod prototype.


This file has been included (was included all the way).

Changed the offending line.
FROM:
if (Win = (struct Window *)DoMethod(WinObj, WM_OPEN, NULL))

TO:
if ((ULONG)Win = DoMethod(WinObj, WM_OPEN, NULL))

The WARNING has now gone, but I do have a feeling that it is not a correct way of doing things. Am I wrong in this respect?

EDIT:
The program compiles and links well. It executes fine, so I assume it is correct now!

Thanks, for all your remarks, wisdom and knowledge. I'm very satisfied.
To me, this topic is closed.

Jettah