Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 112
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Passing a float array to a library

Passing a float array to a library

Discuss PocketC for Palm OS (including Desktop Edition)

Postby flinseisen on Sat Nov 12, 2005 3:09 pm

I would like to create a library that operates on a float vector. My real goal is to get compile Fourier-Transform code into a library that can be used with PocketC. Here a simpler example:

// this is an example function that I would like to compile
// to a library
void VecAdd(float* pf, int iLen)
{
int i;
for(i=0; i<iLen; i++)
{
pf[i] = pf[i] + 1.0;
}
}

From PocketC I would assume that I call it like:

float fVec[10];
pointer pfPC;
pfPC = fVec;
VecAdd(pfPC, 10);

Now my question:
-How do I access the float pointer in the library? I tried several ways to dereference, but up to now without success. The answer is probably quite simple, just haven't found it yet.

Thank you for your help!

Regards,
Frank
flinseisen
 
Posts: 2
Joined: Sat Nov 12, 2005 3:00 pm
Location: Canada

Postby dewey on Sat Nov 12, 2005 5:19 pm

I haven't compiled it, but the code should look something like this.

Code: Select all
void vectorAdd(PocketCLibGlobalsPtr gP) {
  Value pf, cf;
  float sum = 0.0;
  gP->pop(cf); // count of floats
  gP->pop(pf); // pointer to floats
  for (int i=0; i < cf.iVal; i++) {
    Value* item = gP->deref(pf.iVal + i); // pf[i]
    sum += item->fVal;
  }
  gP->retVal->type = vtFloat;
  gP->retVal->fVal = sum;
}
dewey
Site Admin
 
Posts: 749
Joined: Sun Oct 21, 2007 5:12 am

Postby flinseisen on Sat Nov 12, 2005 11:19 pm

Thank you very much dewey!

Your code works well - just one more question:

// this code works
gP->addLibFunc("vecmult", 2, vtInt, vtInt);
// void vecmult(float pointer pf, int iCount)
void vecmult(PocketCLibGlobalsPtr gP) {
Value pf, cf;
gP->pop(cf); // count of floats
gP->pop(pf); // pointer to floats
for (int i=0; i < cf.iVal; i++)
{
Value* item = gP->deref(pf.iVal + i); // pf[i]
item->fVal *= 2.0f;
}
}

// this variant seems to work too - any issues that you see?
void vecmult(PocketCLibGlobalsPtr gP) {
Value pf, cf, *vpf;
gP->pop(cf); // count of floats
gP->pop(pf); // pointer to floats
vpf = gP->deref(pf.iVal); // get a value pointer
for (int i=0; i < cf.iVal; i++)
{
vpf[i].fVal *= 2.0f;
}
}

My reason for asking is that I personally prefer the second version, as it is closer to "normal" C style code.
flinseisen
 
Posts: 2
Joined: Sat Nov 12, 2005 3:00 pm
Location: Canada

Postby dewey on Tue Nov 15, 2005 3:49 am

PocketC memory isn't guaranteed to be contiguous, so you need to call deref for each Value.
dewey
Site Admin
 
Posts: 749
Joined: Sun Oct 21, 2007 5:12 am


Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 2 guests

cron