• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [ObjC newbie]: dereferencing pointer to incomplete type
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ObjC newbie]: dereferencing pointer to incomplete type


  • Subject: Re: [ObjC newbie]: dereferencing pointer to incomplete type
  • From: "Alastair J.Houghton" <email@hidden>
  • Date: Mon, 4 Aug 2003 10:34:16 +0100

On Monday, August 4, 2003, at 09:55 am, Rob Kuilman wrote:

I tried the changes you suggested, however, that's not working for me at all.
the 'version' element was my bad, sorry about that, it was supposed to be 'myInt'

It's real weird to see that the things i was used to do so often in C(++), don't work in Objective-C...
but, ok, that's not the point :)

All of the things that work in C will work in Objective C, because Objective C is just C with a few OO extensions, unlike C++, which differs from C in a variety of subtle ways.

the error i get now is 'sizeof applied to an incomplete type' in this line:
_myData = (struct _RK_MY_STRUCT_ * )malloc(sizeof(struct _RK_MY_STRUCT_));

That's because you haven't declared struct _RK_MY_STRUCT_; you've declared _RK_MY_STRUCT_ as a typedef of an anonymous struct. Incidentally, I take it that you are aware that identifiers beginning with underscores are generally speaking reserved for use by the C/ObjC run-time, the major exception being member variables of classes or structures...

(the first 'struct' word, had to be put in, otherwise it would give me tons of other errors.)

followed by my good ol' 'dereferencing pointer to incomplete type'.

That's what you'd expect, because struct _RK_MY_STRUCT_ isn't the same thing as _RK_MY_STRUCT_, at least not in C and ObjC.

Something like

typedef struct {
int myInt;
char myChar[124];
char reserved[384];
} RK_MY_STRUCT;

// Then in your function
_myData = (RK_MY_STRUCT *) malloc (sizeof (RK_MY_STRUCT));

should work fine. If it doesn't, then it's probably because the compiler hasn't seen the typedef (perhaps you haven't #included or #imported the right header file?).

Writing "struct" before the RK_MY_STRUCT will actually make the compiler treat it as a forward declaration of a structure with the tag RK_MY_STRUCT, the definition of which it hasn't seen yet; since it hasn't seen the definition, it can't compute the size of it (because it doesn't yet know what the structure contains).

Kind regards,

Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: [ObjC newbie]: dereferencing pointer to incomplete type (From: Rob Kuilman <email@hidden>)

  • Prev by Date: format specifiers
  • Next by Date: RE: format specifiers
  • Previous by thread: Re: [ObjC newbie]: dereferencing pointer to incomplete type
  • Next by thread: (no subject)
  • Index(es):
    • Date
    • Thread