Re: [ObjC newbie]: dereferencing pointer to incomplete type
Re: [ObjC newbie]: dereferencing pointer to incomplete type
- Subject: Re: [ObjC newbie]: dereferencing pointer to incomplete type
- From: Rob Kuilman <email@hidden>
- Date: Mon, 4 Aug 2003 10:55:52 +0200
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 :)
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_));
(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'.
the rest of the code is as you suggested.
Robert K.
-----------------------------{ Official Cocoa Newbie!
}-----------------------------
web:
http://halfduplex.net/
email: email@hidden
On Monday, August 4, 2003, at 04:33 AM, publiclook wrote:
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.