0

I'm sorry, I'm slightly embarrassed that I have to ask this question. I can't seem to discover why I'm using the -> command in C wrong. I know that 'x->y' is equivalent to '(*x).y', but for some reason I am using it incorrectly in my first project for class.

For perspective, I have 28 errors in my project; 26 are from this misunderstanding, and two are from a for loop with initial declaration outside of C99 mode - this doesn't matter to me as I have to transfer this code over to a Unix machine to compile it there, so these errors won't occur.

The specific error I'm getting is this:

C:\Users\Nick\Documents\School\CS449\Programs\Project 1\EXIF Viewer\main.c|78|error:invalid type argument of '->' (have 'struct tag')|

Of the 26 errors, every single one is structured like this, but some say (have 'struct header') while others say (have 'struct tag').

I'm going to include the entirety of my code at the bottom of this post, but the relevant struct declarations and calls are set like this:

struct tag the_tag;//The reused tag

^This is a global struct variable

struct header intro; //Bytes 0-19 of the program

^This is a local struct header in int main(argc, **argv){}

Some of the lines that are giving me these errors are:

56:  else if(intro->endianness[0] != 'I')
74:  if(the_tag->tag_identifier == (0x010F))
78:  printf("Manufacturer: %s\n", the_tag->data);
98:  else if(the_tag->tag_identifier == (0x08769))
125: else if(tagger->tag_identifier == 0x8827)

Can someone please explain where my understanding of this dereferencer in C is incorrect, and why these calls are working like I expect them to? I'm quite confused, and my google/searching skills have turned up nothing in regards to the event. Thank you for your help.

Here is my pastebin: http://pastebin.com/ck8ThFLG

4

1 回答 1

4

a->b相当于(*a).b

因为introis 是 type struct header,所以它的成员可以简单地访问,.而(比如说)一个type 的变量->需要一段时间。intro_ptrstruct header*

于 2013-09-29T18:06:17.273 回答