Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: Jose on September 04, 2004, 07:22:18 PM

Title: Is this "Invalid types for assignment" freaking out?
Post by: Jose on September 04, 2004, 07:22:18 PM
A piece of code similar to the initialization part of a bigger proggie I'm trying to make, wich gets that error, is below.
Stupidly enouph I'm getting that message with any library I open.
Dunno if it's the same thing, but I'm also getting "dereferenced object is incomplet" or something like that, when I try to assign some values to a tagitem array. (But let's leave this one for later...)

What do you think the problem is :-?

Code: [Select]
#include <stdio.h>


int main (int argc, char **argv)

{

struct Library *UtilityBase;

if (!(UtilityBase=OpenLibrary (&quot;utility.library&quot;,0L)))
   {printf(&quot;couldnt open utility library\n&quot;);
   exit();}
printf(&quot;library opened successfully\n&quot;);
CloseLibrary (UtilityBase);
exit();
}
 
Title: Re: Is this "Invalid types for assignment" freaking out?
Post by: Piru on September 04, 2004, 07:28:02 PM
You lack prototypes for various functions, namely OpenLibrary, CloseLibrary, and exit.

By default C compiler defaults to something like "int foo(...)", and obviously you can't assign integer to pointer with a cast.

Add
Code: [Select]

#include <stdlib.h>

#include <proto/exec.h>


stdlib.h for exit(), which btw needs an argument (return value).

proto/exec.h for OpenLibrary and CloseLibrary.
Title: Re: Is this "Invalid types for assignment" freaking out?
Post by: Karlos on September 04, 2004, 07:30:34 PM
@Jose

If you don't #include any headers for OS libraries, the compiler has no idea what a 'struct Library' is. Furthermore, it has no clue what OpenLibrary() returns and (in infuriating C legacy madness) assumes int.

It then manages to see that the "pointer to some unknown 'struct Library'" is not compatible with type 'int'.

You should include and also any headers specific to any libraries you want to use.

The same problem is likely the cause of your TagItem woes. If you do not include the (or whatever it is), the compiler cannot know what "struct TagItem" looks like and so you cannot access any of its members.
Title: Re: Is this "Invalid types for assignment" freaking out?
Post by: Karlos on September 04, 2004, 07:31:25 PM
As always, the ever vigilant Piru beat me to it :-D
Title: Re: Is this "Invalid types for assignment" freaking out?
Post by: Piru on September 04, 2004, 07:33:45 PM
@Karlos

I'm always fast after sauna. :-)
Title: Re: Is this "Invalid types for assignment" freaking out?
Post by: Jose on September 04, 2004, 07:38:47 PM
 :lol:
Thx.

I'm finding it very annying to having to look around for includes everytime... :-o
Title: Re: Is this "Invalid types for assignment" freaking out?
Post by: Karlos on September 04, 2004, 07:45:48 PM
@Jose

C is a very minimalist language. Without including any headers, the only types available are the elemental ones (char, int, short, long and their signed/unsigned qualified versions, float, double and all their pointers). The only functions and structures available (without including any headers again) are the ones you write in your .c file :-)

It is partially due to this minimalist simplicity that C is equally loved and hated :-)
Title: Re: Is this "Invalid types for assignment" freaking out?
Post by: Karlos on September 05, 2004, 12:19:17 AM
Quote

Piru wrote:
@Karlos

I'm always fast after sauna. :-)


Ineed. But surely all that moisture must play havoc with your computer :-D