Re: returning char* from an obj-c method
Re: returning char* from an obj-c method
- Subject: Re: returning char* from an obj-c method
- From: crucial felix <email@hidden>
- Date: Sun, 23 Feb 2003 20:05:12 -0500
On Sunday, February 23, 2003, at 07:56 PM, Scott Anguish wrote:
is it as simple as that you're not actually allocating the memory for
the types[] char array?
forgive me, but my real working experience with c is pretty small...
On Sunday, February 23, 2003, at 07:39 PM, crucial felix wrote:
hi,
I am using a framework that wraps a c library with obj-c methods.
-(char*)fulltypes
{
int i=0;
int size = [args count] + 2; // , \0
stepping through in the debugger, the int size was correct.
char types[size];
and i thought that's all i have to do.
types[0] = ',';
for(i = 0; i < [args count]; i++) {
types[i + 1] = [[args objectAtIndex: i] type]; // each
arg::type returns a char
}
types[size - 1] = '\0';
NSLog(@"built types: %s",types);
it prints out correctly here.
return types;
}
but once returned, its garbage.
what can happen on the way to returning the obj-c method ?
thanks.
you can see the result logged here:
2003-02-23 19:20:06.646 Untitled[24544] built types: ,siiisfssiiisf
but here is the method being called from my unit test:
NSLog(@"fulltypes: %s",[msg fulltypes]);
2003-02-23 19:20:06.646 Untitled[24544] built types: ,siiisfssiiisf
2003-02-23 19:20:06.646 Untitled[24544] fulltypes :
\\370\\u02c7\\317\\uf8ffisfs\\352\\307\\u02db\\331sf
the char* didn't survive being returned ?
the header for -(char*)fulltypes is correct. ( a common problem )
does anybody have any ideas why my string turned to gibberish ?
some kind of encoding mismatch, or total garbage ?
thank you, oh wise ones.
-felix
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
-felix
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.