0

I wan't to use some C source in my Objective-c proj but the source lacks a header file. I get a "implicit declaration of function" warning when building, however the app launches fine and works fine up until I try to call one of the C functions. Now that it crashes could be cause somethings wrong with the args I pass, I haven't investigated that further yet. But:

Is there a way to get rid of the build warning?

Am I on the right track? Meaning that the C source will be usable even without the header file..


Some background :

I'm trying to use a GPL dynamic C library in my Objective-c project (iPhone). With no C experience the C code itself is a bit to low level for me to be able to effectively use. However the C lib also contains some higher level example programs which I can understand what they are doing and I think (hope) also modify to suit my needs. This example program is just a source file fired from a shell script wrapper. No header file.

4
  • Why not just make a header file for it? Commented Dec 11, 2010 at 12:34
  • 1
    Objective C is a C superset, so any valid C is valid Objective C. refer to @pablo's answer on how to do it Commented Dec 11, 2010 at 12:44
  • @Karl Knechtel: that was my first thought actually. Tried it out yday on a hunch when very tired and got some errors so I ditched that idea. Turns out the .h file I created in Xcode had @implementation in it instead of @interface and I was too tired to notice :P Commented Dec 11, 2010 at 13:04
  • I've changed my references to "C class" to say C source etc to not further spread the confusion. Commented Dec 11, 2010 at 13:18

1 Answer 1

3

First of all, there is no such thing as a C class.

If you mean just calling a C function you can add the function prototypes in your Objective-C code.

Let's say you need to call a function f that returns an int and takes a char parameter that is defined in your .c file.

In your .m file, where you will call the function, add the following line:

int f(char);

You will get rid of the implicit declaration of function.

Alternatively, you can write all function prototypes in a custom made .h file of your own in case you decide you need to use those functions in other compilation units as well.

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry bout calling it a "C class", but I said "no C experience" =) What do you say if you want to reference the file that contains the function(s)? "C implementation file"?
@Oskar Lund: correct. You can say "C source file", "C function definition file" or "C implementation file". Hope it helps.
Otherwise, Thank you. I went with creating a new header file for it and it builds without errors now. Still crashes but I'm sure that's unrelated.
I've changed my references to "C class" to say C source etc to not further spread the confusion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.