Welcome, Guest. Please login or register.

Author Topic: Is this "Invalid types for assignment" freaking out?  (Read 970 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Is this "Invalid types for assignment" freaking out?
« 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();
}
 
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Is this "Invalid types for assignment" freaking out?
« Reply #1 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.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Is this "Invalid types for assignment" freaking out?
« Reply #2 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.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Is this "Invalid types for assignment" freaking out?
« Reply #3 on: September 04, 2004, 07:31:25 PM »
As always, the ever vigilant Piru beat me to it :-D
int p; // A
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Is this "Invalid types for assignment" freaking out?
« Reply #4 on: September 04, 2004, 07:33:45 PM »
@Karlos

I'm always fast after sauna. :-)
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: Is this "Invalid types for assignment" freaking out?
« Reply #5 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
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Is this "Invalid types for assignment" freaking out?
« Reply #6 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 :-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Is this "Invalid types for assignment" freaking out?
« Reply #7 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
int p; // A