0

I have a struct defined as:

typedef struct _InstNode{
    
    InstInfo* instinfo;
    struct _InstNode *dep1;
    struct _InstNode *dep2;
    bool is_exit;
    bool is_entry;
    unsigned inst_latency;
    unsigned  depth_latency;
} InstNode;

and this is instnode_array :

InstNode *instnode_array;
    instnode_array = (InstNode*)malloc(sizeof(InstNode)*numOfInsts);

Now I'm trying to do the following:-

instnode_array[i].dep1 = instnode_array[j];

I'm getting this error:

incompatible types when assigning to type 'struct _InstNode *' from type 'InstNode {aka struct _InstNode}'

  instnode_array[i].dep1 = instnode_array[j];
Community
  • 1
  • 1
Ameer khan
  • 47
  • 7

1 Answers1

3

TL;DR Note Honor the data types.

instnode_array[j] gives you a struct _InstNode whereas, dep1 is of type struct _InstNode *.

You may want to write

instnode_array[i].dep1 = &(instnode_array[j]);

if that make sense to you.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
  • another related question If I may: When I write the field dep1 this way: `struct _InstNode *dep1;` It gives me error but, when I write it this way : `struct _InstNode* dep1;` It builds with no errors.. any explanation? – Ameer khan May 27 '17 at 16:24
  • @Ameerkhan I don't see any reason. Check [this answer](https://stackoverflow.com/a/44055041/2173917) – Sourav Ghosh May 27 '17 at 16:27
  • I checked it 30 minutes ago and didn't find any reason also. I think it is just an eclipse thing. – Ameer khan May 27 '17 at 16:30
  • @Ameerkhan No error should happen. If you told us _what_ error you get, we could assess it further. When telling people that something gives you an error, always tell them what it is. – underscore_d May 28 '17 at 09:43