• 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: A Matrix collection class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A Matrix collection class


  • Subject: Re: A Matrix collection class
  • From: Ondra Cada <email@hidden>
  • Date: Wed, 8 May 2002 15:52:03 +0200

On Wednesday, May 8, 2002, at 02:46 , email@hidden wrote:

My main problem with multidimensional arrays is figuring out how to convert a straight void* to them - I can never persuade C to convert to int[x][y][]...

On the plain C level, you want to convert to int* instead of int[], so something like ((int*)[x][y]) should work. Remember, in plain C, a[x] and *(a+X) are equivalent expressions. Also, for some not quite obvious reason,
this works for me only if typedef is used (anybody knows why cast '((*int)
[5][3])' does not work? It should, IMHO!):

27 /tmp> cat q.c
#include <stdio.h>

int main() {
int i,j,k,a[10][5][3];
void *ptr=(void*)a;
typedef int (*foo)[5][3];

for (i=0;i<10;i++) for (j=0;j<5;j++) for (k=0;k<3;k++) a[i][j][k]=i^j^k;
for (i=0;i<10;i++) for (j=0;j<5;j++) for (k=0;k<3;k++)
if (a[i][j][k]!=((foo)ptr)[i][j][k]) {
printf("Oops at %d,%d,%d\n",i,j,k);
return 1;
}
printf("OK\n");
return 0;
}
28 /tmp> cc -Wall q.c && ./a.out
OK
29 /tmp>

And while I know I can use my own index calculation, or an NSDictionary, I was hoping (as I said) for something less ugly. An object that does that for me, for example.

I personally know of none available, but my estimate for writing and debugging one is half an hour at most for relatively inexperienced programmer, so I would not see it as a big problem.
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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: A Matrix collection class
      • From: Nat! <email@hidden>
    • Re: A Matrix collection class
      • From: email@hidden
References: 
 >Re: A Matrix collection class (From: email@hidden)

  • Prev by Date: Re: A Matrix collection class
  • Next by Date: Never Mind the File Extensions
  • Previous by thread: Re: A Matrix collection class
  • Next by thread: Re: A Matrix collection class
  • Index(es):
    • Date
    • Thread