• 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: C to Objective-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C to Objective-C


  • Subject: Re: C to Objective-C
  • From: Ondra Cada <email@hidden>
  • Date: Fri, 4 Oct 2002 17:56:56 +0200

On Friday, October 4, 2002, at 04:56 , Jon wrote:

How do I write this C call in Cocoa?

/* sample */
float Y[2];
float X[2];

X[0] = 5;
X[1] = 1;
Y[0] = 2;
X[1] = 3;

vertices(X, Y, 2);

/* Other file */

void vertices(float xVert[], float yVert[], int TOTAL)
{
int i;
for(i=0; i < TOTAL; i++) {
glTranslatef(xVert[i], yVert[i], 0.0);
}
}

What about

float Y[2];
float X[2];

X[0] = 5;
X[1] = 1;
Y[0] = 2;
X[1] = 3;

vertices(X, Y, 2);

/* Other file */

void vertices(float xVert[], float yVert[], int TOTAL)
{
int i;
for(i=0; i < TOTAL; i++) {
glTranslatef(xVert[i], yVert[i], 0.0);
}
}

? I guess that would be the simplest way. And since it is self-evidently a ported code, it seems quite improbable the lact of encapsulation/polymorphism/inheritance would really matter.

OTOH, if you wanted to refactor badly, you might also consider NSPoints and similar beasts (incl. NSArrays, which depends on the efficiency needed)
.

Finally, if you insist,

- (void)verticesX:(float[])xVert Y:(float[])yVert T:(int)TOTAL;

might work (never tried), whilst

- (void)verticesX:(float*)xVert Y:(float*)yVert T:(int)TOTAL;

would work for sure (also never tried, but many times used similar constructions).
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.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.
References: 
 >C to Objective-C (From: Jon <email@hidden>)

  • Prev by Date: Re: NSNetService addresses returns empty array
  • Next by Date: Re: Insert text at end of Textview
  • Previous by thread: Re: C to Objective-C
  • Next by thread: Re: C to Objective-C
  • Index(es):
    • Date
    • Thread