![]() |
#1 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
![]()
Hi.
If I have a [blackbox] method in c++ (which I'm porting to c) First am I setting up the right variables to put in it. Code:
short audioBuffer[someLength]; float *signal; float frequency, sr; int vector_size; something? delayed_signal; float highpass(float* sig, float freq, float *del, int vecsize, float sr) { blah } ( A POINTER TO A FLOAT, a float, A & of a * ???, an int, a float) I'm a bit foggy on the pointers though. yes I am off have RTfriendlyM ![]() Thanks. I understand they represent an address rather than the value itself and I can get the first one right I think, is the second one a ** or a & or what? The transition to c is a slow one. ![]() also, are there any caveats I should watch for during the conversion to c? (err just the big lumps) thanks a lot ![]() Last edited by twobob; 07-14-2012 at 09:50 PM. Reason: added some variable instancing, and extra notes |
![]() |
![]() |
![]() |
#2 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
I'm reading here: http://en.wikibooks.org/wiki/C_Progr..._dereferencing
Pointers in Function Arguments Often we need to invoke a function with an argument that is itself a pointer. In many instances, the variable is itself a parameter for the current function and may be a pointer to some type of structure. The ampersand character is not needed in this circumstance to obtain a pointer value, as the variable is itself a pointer. In the example below, the variable pStruct, a pointer, is a parameter to function FunctTwo, and is passed as an argument to FunctOne. The second parameter to FunctOne is an int. Since in function FunctTwo, mValue is a pointer to an int, the pointer must first be dereferenced using the * operator, hence the second argument in the call is *mValue. The third parameter to function FunctOne is a pointer to a long. Since pAA is itself a pointer to a long, no ampersand is needed when it is used as the third argument to the function. Code:
int FunctOne( struct SomeStruct *pValue, int iValue, long *lValue ) { /* do some stuff ... */ return 0; } int FunctTwo( struct someStruct *pStruct, int *mValue ) { int j; long AnArray[25]; long *pAA; pAA = &AnArray[13]; j = FunctOne( pStruct, *mValue, pAA ); return j; } Last edited by twobob; 07-14-2012 at 09:57 PM. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
err so... like...
Code:
short audioBuffer[someLength]; float *signal; float frequency = 3000.0; float sr = 8000.0; int vector_size = 32765; something? delayed_signal; signal = audioBuffer[offsetofsomekind]; delayed_signal = audioBuffer[offsetofsomeOTHERkind]; float result = highpass(signal, frequency, *delayed_signal, vector_size, float sr); Last edited by twobob; 07-14-2012 at 10:05 PM. Reason: legibility |
![]() |
![]() |
![]() |
#4 |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
![]()
One thing to remember in calling C functions is that the CALLED function receives a COPY of everything that was passed to it. Because a function can only return a single value (which is often just an error code), returning MORE stuff requires that the CALLER pass an address of a CALLER's variable or structure in which the CALLED function can place the extra return value(s).
Addresses are passed in pointer variables (or with the address of a non-pointer var). If the CALLER wants to pass the ADDRESS of a var "int myVar", then it would pass &myVar in the call (in place of a pointer var parameter "int *pVar). The CALLED function would get a COPY of that address in pVar (which still points at the same address), and it would write to that address with *pVar=666. That value is immediately stored into the CALLER's myVar variable (even before returning to it). To return a lot of data, the CALLER can pass the address of a structure instead. It can set myVar inside myStruct like this: myStruct.myVar=666. Then it can pass &myStruct in a parameter in place of struct *pStruct. The CALLED function gets a copy of pStruct (which points to the CALLERS myStruct). To access data using a structure pointer (address of a structure), do this: pStruct->myVar=666. C++ has other funny (non-C) stuff involving &vars inside functions, which is just shorthand for noobs to avoid all those pesky pointer dereferences. Clear as mud, right? The way to learn it is to DO it. Write some tiny little proggies that futz with pointers of various types and see what they do. Last edited by geekmaster; 07-14-2012 at 10:25 PM. |
![]() |
![]() |
![]() |
#5 | |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
Quote:
![]() but I just cant seem to figure out if I cast or what that third argument? Ah well. Ill figure it out! thanks for the 101 |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Carpe diem, c'est la vie.
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
|
![]() Quote:
In your example: float result = highpass(signal, frequency, *delayed_signal, vector_size, float sr); the * on *delayed_signal means delayed_signal is a POINTER that contains an ADDRESS. It should be DEFINED like this: float *delayed_signal; The * in front of it dereferences it returning the VALUE that it points to. Inside that call the way you are doing it In the above call, the third parameter is just a value (not an address) being sent in the call. Now, if the function PROTYPE called for a third parameter of type "float *delayed_signal", then you are calling it incorrectly with a "*" in the call. Instead should pass either a pointer var that it is sending the ADDRESS of the delayed_signal var in the call On a side note, some people like to move the * (as in "float* signal;") but that can be CONFUSING when there are multiple variables on that line. For example: float* a,b,c; looks like a,b,c are all of type "float*", but it really means float *a,b,c; where only a is a pointer var. So do not be tempted to DO that then. Okay? Any help? Or just more befuddlement? I strongly recommend a little book called K&R. I fondled my first edition lovingly and repeatedly when it first came out. And read some source code too. A lot can be learned from working source code. Here is a little "C pointers" google fu for you: http://www.openismus.com/documents/c...pointers.shtml And deeper geekness pointer fu for you too: http://www.thegeekstuff.com/2012/01/...ed-c-pointers/ Last edited by geekmaster; 07-14-2012 at 11:01 PM. |
|
![]() |
![]() |
![]() |
#7 |
BLAM!
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 13,506
Karma: 26047190
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
Also, try not to get bitten in the ass by the scope of your variables, that may need to be taken into account, depending on how your stuff is set up
![]() |
![]() |
![]() |
![]() |
#8 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
Thanks Guys. I'll have a play
|
![]() |
![]() |
![]() |
#9 | |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
Quote:
|
|
![]() |
![]() |
![]() |
Tags |
development, kindle, noob |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Nooby Questions about the PE | stevesr0 | enTourage eDGe | 4 | 07-20-2011 11:37 PM |
Memory question... | tlo07 | Nook Developer's Corner | 3 | 04-02-2011 07:32 PM |
nooby has lots of questions | StickMaker | Amazon Kindle | 4 | 02-27-2011 11:34 AM |
Nooby Kobo question | BBel | Calibre | 4 | 06-27-2010 01:07 PM |
nooby here, have a few questions? | baker101 | Sony Reader | 7 | 12-17-2006 12:16 PM |