Re: Using C?
Re: Using C?
- Subject: Re: Using C?
- From: rsharp <email@hidden>
- Date: Thu, 14 Jun 2001 10:56:43 -0500 (CDT)
On Wed, 13 Jun 2001 email@hidden wrote:
>
How much C can one use in an Objective-C program and what are the
>
limitations? I've included a straight C based method in an app I'm
>
writing -- side by side with my Objective C methods -- and it seems to
>
work without too many problems.
>
>
The only real problem I've experienced with my C method is that it seems
>
unable to call methods of access variables in the same object. Calling
>
stuff like [self: doSomething] within the C method results in the warning
>
"self undeclared." Is it not possible to mix up C and Objective-C like
>
this? Also, for example, any variables declared in the header file for
>
the object are also inaccessable in the C function/method.
From what I'm reading, it sounds like you have a set of Obj-C objects
(with their data and methods) and also a set of straight-C functions that
aren't methods of the object?
This would be the same problem in C++.
You can definitely have plain vanilla C functions, but not being methods
of your object, they'll have no knowlege of that object. You could
potentially pass that object in as a param, but I'd say that's a bad
design. You typically want your object to contain all the methods
necessary to manipulate its data.
However, you can then use your plain vanilla C functions as support
functions that your methods can use to do quantities of work. Such
functions would be "generic" in that they'd have no knowlege of your
objects, but could still manipulate your object's data (which you'd
obviously pass in as generic typed parameters).
e.g. an Obj-C object could contain a simple integer array. It's various
initialize methods could then tap into a C function that could fill the
integer array as needed.
HTH,
Rick Sharp
Instant Interactive(tm)