Re: (RS)What's the type of a selector?[3]
Re: (RS)What's the type of a selector?[3]
- Subject: Re: (RS)What's the type of a selector?[3]
- From: PGM <email@hidden>
- Date: Sat, 28 Oct 2006 00:31:25 -0400
To make it even clearer:
SEL is indeed a struct, but a struct containing nothing but a char*.
If I define an example struct consisting of nothing but a char *,
logging this with %s indeed gives the string put into the struct.
typedef struct PMText {
char* text;
} PMText;
If I then use this and log it with %s:
char someText[] = "hello world";
PMText foo;
foo.text = someText;
printf("%s", foo);
This reproduces "hello world", as expected with no magic involved,
just plain C.
The important point is that if the documentation says a SEL is
defined as a struct, it may be wise to treat it as such, as maybe at
some point the exact definition of the struct may be changed (though
this is unlikely for something as basic as SEL). Let's say that I
would want to expand my PMText with some other variable:
typedef struct PMText {
float value;
char* text;
} PMText;
If I now use the same code as above to log the struct, my app
crashes. However, accessing the structs string as it should, so
using .text is no problem, and the new implementation of PMText does
not break the old one if properly used.
Patrick
On 27-Oct-06, at 23:05 PM, Roland Silver wrote:
On Oct 27, 2006, at 8:30 PM, Chris Suter wrote:
Hi,
Looks like you should read some C books.
It's a pointer to an structure.
It's not a char * and NSLog ("%s", @selector (foo)) will not work
as someone suggested earlier.
Either use %p for a pointer or use %s with sel_getName or use %@
and NSStringFromSelector.
This is all in the documentation and you really don't need us to
help you.
- Chris
Well, Chris...
First: I've read Kernighan/Ritchie and Harbison/Steele; will they do?
Second: I'm sure there isn't a book on C that talks about @selector
or NSLog, which are Cocoa features, not C features.
Third, NSLog ("%s", @selector (foo)) DOES work, as Aaron Hillegass
suggested: try it for yourself; I did! Here ya go:
@implementation type
- (void)awakeFromNib {
NSLog(@"%s", @selector(awakeFromNib));
}
@end
That is the important part of a project that compiles and runs. The
result from the run log is:
[Session started at 2006-10-27 20:46:42 -0600.]
2006-10-27 20:46:43.246 selectorType[1489] awakeFromNib
Fourth: It doesn't look to me like @selector is a pointer to a
struct (if that's what you meant), it looks like a pointer-to-char,
i.e. a C-string.
Fifth: Thanks for telling me that it's "all in the documentation"
and I don't need the list members to help me. I searched around at
length in the "documentation" before putting my question to the
list, but didn't find the answer anywhere I looked.
--Roland Silver <email@hidden>
--------------------------------------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40sympatico.ca
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden