• 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: publiclook <email@hidden>
  • Date: Sun, 3 Aug 2003 22:33:15 -0400

On Sunday, August 3, 2003, at 05:37 PM, Rob Kuilman wrote:

Hey all!

I've been switching from Carbon/C++ tot Cocoa/Obj-C, learning goes well, and so far is easier than i expected it to be.
However, i have a problem (obviously), here comes the code first:

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

@interface myInterface : NSObject
{
_RK_MY_STRUCT_ * _myData;
}


- (void) myfunction {
// ...
_myData = (_RK_MY_STRUCT_ * )malloc(sizeof(struct _RK_MY_STRUCT_));
myData->version =1; // <--- **** _RK_MY_STRUCT_ HAS NO VERSION ELEMENT!!!
// ...
}

Above I show several improvements to your example, but it is never going to work until you add a version element to the _RK_MY_STRUCT_ type or change the element you are trying to set.

In Objective-C, the default accessibility for instance variables is @protected and it is BEST to leave it that way. If you declare instance variables @private you are shutting the door on future sub-classers and you probably can not anticipate everything they might need. @public is a bad idea because it violates encapsulation.

Objective-C is a super-set of C99 and NOT C++. As far as I know you can not declare a new structure label within a class interface just like you can't do it within a function in C. Structure labels have global scope in C.

//
// in my header:
//
@interface myInterface : NSObject {
@public
struct _RK_MY_STRUCT_ {
int myInt;
char myChar[124];
char reserved[384];
};

// code
@private
struct _RK_MY_STRUCT_ * myData;
}

//
// in my code:
//
- (void) myfunction {
// ...
myData = malloc(sizeof(struct _RK_MY_STRUCT_));
myData->version =1;
// ...
}

Normally, in C, this would work for me... however, while trying to compile it, i get the following error:
'dereferencing pointer to incomplete type'

and THAT's what im not able to figure out. So if anyone wants to enlighten me on Objective-C or tell me that i've had
a too long vacation, i'd be very grateful.

Thanks in Advance,

Robert K.

-----------------------------{ Official Cocoa Newbie! }-----------------------------
web: http://halfduplex.net/
email: email@hidden
_______________________________________________
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.
_______________________________________________
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.

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

  • Prev by Date: Help: Waiting for other thread to finish?
  • Next by Date: Dock menus
  • Previous by thread: [ObjC newbie]: dereferencing pointer to incomplete type
  • Next by thread: Re: [ObjC newbie]: dereferencing pointer to incomplete type
  • Index(es):
    • Date
    • Thread