 |
 |
C question
|
 |
|
 |
|
Junior Member
Join Date: Nov 2000
Status:
Offline
|
|
If I want to use simple C functions in a Obj-C/cocoa app how do I go about doing that?
Can I just write the functions in a .c file and import them with #import?
-Max
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status:
Offline
|
|
Yep. You can use #include too; it works like normal. #import automatically protects against multiple inclusions; that's the only different from #include.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Status:
Offline
|
|
You could import the .c file, but most common programming practice is to put the function prototypes in a .h file, and then include it in both the .c file and whatever else you plan on using the functions in. The linker will take care of the rest in the build phase.
Also note that in most standard C programs, #import is not used, but instead they do something like this:
Code:
[my_func.h]
#ifndef MY_FUNC_H
#define MY_FUNC_H
/* code goes here */
#endif /* MY_FUNC_H */
This also protects from multiple inclusions. Keep this in mind if you write any code you plan on running on OS's other than OS X, because other compilers will either die or issue a warning for the use of #import statements. Read Apple's compiler documentation in the /Developer folder for more details.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Well, in a general answer to your first question, you can use any C code in an Objective-C Cocoa app. Objective-C is a superset of C, so any valid C code is also valid Obj-C code.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status:
Offline
|
|
Yep, you can use any C code you want to. Just make sure that any functions you write are outside of the @interface...@end and @implementation...@end sections, and it'll work fine.
In my current project, i've got one file with a pile of C string functions, strings.m, and a file strings.h that various classes import as needed. It works perfectly.
|
|
All words are lies. Including these ones.
|
| |
|
|
|
 |
|
 |
|
Moderator Emeritus 
Join Date: Mar 2001
Location: Austin, MN, USA
Status:
Offline
|
|
I have a .c file from a person in one of my classes. When compiled, it is a text based, interactive program.
How would I go about giving this a GUI? I don't know any C yet, but I have done a few tutorials for Project builder.
I was thinking I could have a push button that would start it, and the rest of the app would just run inside a text field. Is this possible?
------------------
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
Yup, it's very possible Xeo. That happens with stuff like OpenUp and other Gooey programs. Of course, modeling a true interface around the app is your best bet...
What kind of program is it?
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Moderator Emeritus 
Join Date: Mar 2001
Location: Austin, MN, USA
Status:
Offline
|
|
It's a cryptanalysis project. Basically, once you compile it, and run it, it opens to a blank screen. You have to hit ? (question mark) to get a small menu which tells you the kind of things that can be done.
I have no idea how to give it a GUI. I didn't write it and even in Terminal it's crap. (actually, I couldn't get it compiled correctly on this either, I had to use my network's Unix server via telnet.)
It's probably best if I let the program die.  I was just curious if it was possible.
Thanks.
------------------
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
No, I don't think you can give programs like that a GUI very easily... Unless you were to rip out the interface and chuck the backend into your project 
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|