• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSString array to -> char**
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString array to -> char**


  • Subject: Re: NSString array to -> char**
  • From: Thomas Lachand-Robert <email@hidden>
  • Date: Wed, 19 Mar 2003 13:48:22 +0100

Le mardi, 18 mars 2003, ` 09:42 Europe/Paris, Seth Delackner a icrit :


// now we have the strings lengths in front of the array, we want pointers instead
char *p = [data mutableBytes], *q=p;
while (k--) q++ = p + *(int*)q;
q = NULL; // NULL terminated array
return data; // that's all folks
}

OK, I am having difficulty understanding the code on that while line.

Did you mean:

while (k--) {
*q = (int)(p + *(int*)q);
q++;
}

q++ = p + *(int*)q is very foreign c to me. Isn't that assigning the element's address to the address of our index pointer (q)? Don't we want to store the new address in *q, not set q to point somewhere else? My c memory address arithmetic is pretty rusty.


No, but my code was plain wrong here (too quickly typed). Back to the point, we now have a char** (not a char*) at the beginning of the array, but it's filled with the lengths of the strings (as a int*), instead of the locations of the strings. So we have to change that:
char** p = [data mutableBytes], **q = p;
char* firststring = (char*)[data mutableBytes] + (n+1)*sizeof(char*); // location of the first string
while (k--) {// there is k strings remaining
int length = *(int*)q; // get the length of the string
*q = firststring + length;
q++;
}
*q = NULL;

Hope it's easier to read now (and less buggy).

Le dimanche, 16 mars 2003, ` 05:23 Europe/Paris, Seth Delackner a icrit :

A, bonjour ami. Pardonne nous aux Etats Unis pour les actions des idiots dans notre gouvernement maintenant. Nous somme plusieurs qui detestent ce qui approche. (Et pardonne ma francais, ca fait trois ans dhs que j'ai vecu en France.

No need to apologize. There are idiots everywhere.
And my english is not better than your french, I guess.

Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.
_______________________________________________
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.

  • Follow-Ups:
    • Re: NSString array to -> char**
      • From: Seth Delackner <email@hidden>
References: 
 >Re: NSString array to -> char** (From: Seth Delackner <email@hidden>)

  • Prev by Date: Re: Jan Dev Docs
  • Next by Date: Re: Jan Dev Docs
  • Previous by thread: [OT] A different kind of French kiss (was Re: NSString array to -> char**)
  • Next by thread: Re: NSString array to -> char**
  • Index(es):
    • Date
    • Thread