Gentlemen,
I have multiple questions that are relative to each other. The first question involves pointers and how they construct / destruct... See code example below.
I have read that you can increment pointers through what I call memory blocks (similar to arrrays[]) by the following example above. I have a few questions regarding declarations and clearing out pointers...
1. If I declare a pointer "P" as GLOBAL, does the pointer "P" destruct itself every time @ the functions end life cycle?
2. If I declare a pointer "P" as LOCAL with-in the function, does the pointer "P" destruct itself every time @ the functions end life cycle? Upon function re-initilization, does the pointer re-instate itself and "NULL" with no data?
3. If I declare a pointer "P" as STATIC GLOBAL, does the pointer "P" stay in memory and retain its old data independent of the functions life cycle, but can be shared among functions?
4. If I declare a pointer "P" as STATIC LOCAL with-in a function, does the pointer retain its data only with-in its function, never destructs, and does not "NULL"?
If question #4 does not NULL.... how does "NULL" work when using pointers?
Does a pointer "NULL" similar to the example below...
clears out a pointer like...
or does it just null the first memory block only and leaves the remainder memory blocks with left over data like...
Could someone please clarify.
Another question. I want to create a function similar Serial1.readbytes(array, len); See example code below...
How does Serial1.readbytes() take the true array command_receive[] within its function and returns the data in the same array without having to use a pointer called command_receive to return the code...
I want to retain the data in array command_receive[] for use upon the same functions re-initialization. This will allow me to perform an additional task in the place of delay(25) and actually reduce to delay(15). See below for example code...
My purpose is to first confirm my interpretation of pointers. I also want to have some understanding how readbytes(##, 2) is coded with some sort of an example without the dependancy of Serial3 class... just readbytes alone.
Thanks in advance
BLMinTenn
I have multiple questions that are relative to each other. The first question involves pointers and how they construct / destruct... See code example below.
Code:
uint8_t * P;
void do_something(uint8_t len, uint8_t my array[]) {
for(uint8_t i = 0; i<len; ++i) {* P++ = my array[a];
}
I have read that you can increment pointers through what I call memory blocks (similar to arrrays[]) by the following example above. I have a few questions regarding declarations and clearing out pointers...
1. If I declare a pointer "P" as GLOBAL, does the pointer "P" destruct itself every time @ the functions end life cycle?
2. If I declare a pointer "P" as LOCAL with-in the function, does the pointer "P" destruct itself every time @ the functions end life cycle? Upon function re-initilization, does the pointer re-instate itself and "NULL" with no data?
3. If I declare a pointer "P" as STATIC GLOBAL, does the pointer "P" stay in memory and retain its old data independent of the functions life cycle, but can be shared among functions?
4. If I declare a pointer "P" as STATIC LOCAL with-in a function, does the pointer retain its data only with-in its function, never destructs, and does not "NULL"?
If question #4 does not NULL.... how does "NULL" work when using pointers?
Does a pointer "NULL" similar to the example below...
Code:
void some_function{} {...
static uint8_t * P;
P = NULL;
}
Code:
P[0] = NULL;
P[1] = NULL;
P[2] = NULL;
...
Code:
P[0] = NULL;
...
P[1] = 0x02;
P[2] = 0x04;
Could someone please clarify.
Another question. I want to create a function similar Serial1.readbytes(array, len); See example code below...
Code:
uint8_t get_data() {
static uint8_t command_send[4] = {0xfe, 0xc1, 0x35, 0x31};
static uint8_t command_receive[4];
Serial1.write(command_send, 4); //send out a command
delay(25); //give the other side time to respond
Serial1.readbytes(command_receive, 4); //receive incoming data
return command_receive[3]; //return only what is need, throw away what is not
How does Serial1.readbytes() take the true array command_receive[] within its function and returns the data in the same array without having to use a pointer called command_receive to return the code...
Code:
uint8_t * command_receive;
command_receive = Serial1.readbytes(command_receive, 4);
I want to retain the data in array command_receive[] for use upon the same functions re-initialization. This will allow me to perform an additional task in the place of delay(25) and actually reduce to delay(15). See below for example code...
Code:
uint8_t get_data() {
static uint8_t command_send[4] = {0xfe, 0xc1, 0x35, 0x31};
static uint8_t command_receive[4];
Serial1.write(command_send, 4); //send out a command
Serial3.write(command_receive[3], 1); //print result onto LCD;
... perform some other commands....
delay(15); //give the other side time to respond
Serial1.readbytes(command_receive, 4); //receive new incoming data
return command_receive[3]; //return the new data, throw away what is not needed
My purpose is to first confirm my interpretation of pointers. I also want to have some understanding how readbytes(##, 2) is coded with some sort of an example without the dependancy of Serial3 class... just readbytes alone.
Thanks in advance
BLMinTenn