Re: Obj C ...good style
Re: Obj C ...good style
- Subject: Re: Obj C ...good style
- From: Ken Thomases <email@hidden>
- Date: Sat, 25 Oct 2008 21:48:48 -0500
On Oct 25, 2008, at 8:52 PM, Michael wrote:
It seems in this case, both the definitions and the declarations
occur before "main". Is this the usual practice?
In real projects, as opposed to simplistic example code, it is almost
always best to separate things out into separate files. In this case,
main() is usually in a file by itself. It imports the headers for the
functions and class declarations that it needs.
Otherwise, I would say that the relative positioning of main() vs.
other functions in the same file is purely a matter of style. Do it
however you like.
A lot of single-file code is written with functions defined before
they're used just as a convenient way to avoid having to declare them
separately.
Secondly, **if** for example, "drawshapes" were to have been placed
after "main", would the declaration mimic C ( if this is indeed
allowed) ie
void drawShapes (Shape shapes[], int count);
or
void drawShapes (Shape [], int );
If I understand your question, you're simply asking about the syntax
for declaring a function in Objective-C, right? Then, yes, it works
just like it does in C. Objective-C is a superset of C. All valid C
programs are also valid Objective-C programs. Either of the above
declarations would be correct for the function as defined later in the
file.
In fact, the example code you gave uses precious little Objective-C,
at all. The drawShapes function seems to be entirely using the C
subset.
Cheers,
Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden