Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 07-14-2012, 09:40 PM   #1
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,552
Karma: 6021142
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
Question nooby c++ to c question. dereferencing allocated memory variable

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

}
also how do i reference each bit, I can get the obvious stuff but I'm not sure exactly what the second pointers expecting. the first one wants a location in the audio buffer I expect, I can provide that.

( 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 but any help is always appreciated EDIT: Because I still don't get it

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
twobob is offline   Reply With Quote
Old 07-14-2012, 09:42 PM   #2
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,552
Karma: 6021142
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;
 }
Um... What? Read's it several more times. sigh. get's tea

Last edited by twobob; 07-14-2012 at 09:57 PM.
twobob is offline   Reply With Quote
Old 07-14-2012, 10:04 PM   #3
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,552
Karma: 6021142
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
twobob is offline   Reply With Quote
Old 07-14-2012, 10:18 PM   #4
geekmaster
Всё гениальное просто.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 5,069
Karma: 6789001
Join Date: Nov 2011
Location: Щедрость не имеет пределов.
Device: *.*
Arrow C pointer "micro-tutorial"

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.
geekmaster is offline   Reply With Quote
Old 07-14-2012, 10:21 PM   #5
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,552
Karma: 6021142
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:
Originally Posted by geekmaster View Post
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.
Heh. well I am

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
twobob is offline   Reply With Quote
Old 07-14-2012, 10:43 PM   #6
geekmaster
Всё гениальное просто.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 5,069
Karma: 6789001
Join Date: Nov 2011
Location: Щедрость не имеет пределов.
Device: *.*
Arrow C pointers 102

Quote:
Originally Posted by twobob View Post
Heh. well I am

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
I strongly recommend renaming all pointer vars to start with a "p" (for pointer). Either p_var for all lowercase, or pVar for camelCase var names.

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.
geekmaster is offline   Reply With Quote
Old 07-14-2012, 11:23 PM   #7
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 4,902
Karma: 4492229
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW & PW2
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 .
NiLuJe is offline   Reply With Quote
Old 07-15-2012, 11:22 AM   #8
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,552
Karma: 6021142
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
twobob is offline   Reply With Quote
Old 07-15-2012, 11:22 PM   #9
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,552
Karma: 6021142
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:
Originally Posted by geekmaster View Post
Any help? Or just more befuddlement?

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/
It's help and bloody good help. Many thanks, I still haven't mastered it but I'm getting it
twobob is offline   Reply With Quote
Reply

Tags
development, kindle, noob

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 06:13 AM.


MobileRead.com is a privately owned, operated and funded community.