|
|
#1 |
|
use of undeclared identifier
I would like to build a simple interface around some c-code I have. I've spend over two hours now on a seemingly simple problem with Objective C.
It simply seems impossible to call an Objective C function from within a normal c function. If I do, for example: void changeInfo() { [TextField setIntValue:test]; } I get an error that says "Use of undeclared identifier 'TextField'". Whereas if this piece of code would be like this: - (void) changeInfo { [TextField setIntValue:test]; } ... it would work perfectly fine. What am I doing wrong...? |
|
|
|
0
|
|
|
#2 |
|
Your 'TextField' variable isn't global—it's an instance variable of your class.
Objective-C methods have two implicit parameters that you don't see directly in the code: 'self' (a pointer to the object the method is called on) and '_cmd' (the selector of the method being called). When you access 'TextField', the code that gets generated is actually 'self->TextField'. In a plain C function, there can be no implicit parameters, so even if your C function is defined inside your @implementation, it won't be able to find 'TextField', because it doesn't even know what 'self' is. One thing I often do is just make an explicit 'self' parameter in plain C functions, and then access the ivars explicitly with 'self->TextField'. The compiler won't complain about @private or @protected ivars as long as the function definition is within the @implementation of your class. |
|
|
|
0
|
|
|
#3 |
|
Is TextField an iVar? If so, it should be textField because the leading character should only be caps if it's a Class name, not an instance of a class.
The issue you're having is one of the scope of your variables. In your function example, since you haven't passed in a reference to your textField object, your code won't be able to access it. For example, this should work: Code:
void changeInfo( NSTextField *aTextField )
{
[aTextField setIntValue:test];
}
__________________
How to ask good programming questions: Getting Answers
|
|
|
|
0
|
|
|
#4 |
|
Thanks a lot for your comments, it now works!
Code:
void changeInfo( NSTextField *aTextField )
{
[aTextField setIntValue:test];
}
The above suggestion would be quite complex in this specific case, as the c-program involves starting a lot of threads using the pthread library. The thread functions thus can't easily be started with an argument. |
|
|
|
0
|
|
|
#5 | |
|
Quote:
Code:
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void
*(*start_routine)(void *), void *arg)
From the man-page for pthread_create(): The thread is created executing start_routine with arg as its sole argument. |
||
|
|
0
|
|
|
#6 | |
|
Quote:
|
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| thread | Thread Starter | Forum | Replies | Last Post |
| Future use of Leopard (not even SnowLeopard) with iCal+iPhone | ParisParamus | iCloud and Apple services | 0 | Nov 20, 2011 10:51 AM |
| Use of undeclared identifier 'dvController' | lJoct03 | iPhone/iPad Programming | 5 | Oct 18, 2011 08:13 PM |
| How to create a custom property and identifier? | mandude | iPhone/iPad Programming | 2 | Aug 12, 2011 01:37 PM |
| Any use for undeclared @implementations? | zippyfly | Mac Programming | 3 | Sep 29, 2010 02:33 AM |
| Identifying program that make use of multiple cores | skerfoot | Mac Pro | 1 | Jun 23, 2010 12:49 PM |
All times are GMT -5. The time now is 05:57 PM.







Linear Mode

