I believe that because the argument to LCD_String is a char pointer, it is expecting a char pointer as an argument and not some number (even if it is an address). I think the error would go away if you had actually declared "sentence" as a char pointer, place your data at that memory location, and used it as an argument instead.
It is probably unable to figure out whether or not the address given corresponds to the proper memory reserved for a character.
But who cares about warnings anyways. THe software isn't smarter than you are. It could come up with 40 warnings that don't matter because it's a dumb piece of software searching for certain criteria in your code.
I believe that because the argument to LCD_String is a char pointer, it is expecting a char pointer as an argument and not some number (even if it is an address).
I think the error would go away if you had actually declared "sentence" as a char pointer, place your data at that memory location, and used it as an argument instead.
I'm confused. "sentence" is a plain-jane char array. I pass its address to lcd_string as a pointer to the array. How could the compiler not understand that?
And how can I put my array in a char pointer? That makes no sense (to me at least).
Yeah, what I meant was the a pointer has the address as well as the number of memory locations following that address that belong to the pointer, while an address is just an address without the reserved memory information. It was this extra information that the compiler could not match up to with the argument that was declared as a pointer.
Code:
char sentence[16] = "dsPIC 30F4013";
char *senpoint = sentence; //this makes the pointer equal to the address of the first character of "sentence"
//you can also make an array of of pointers
char *senpoint[] = "dsPIC 30F4013" //array size calculated implicitly from string length
char *senpoint[13] = "dsPIC 30F4013" //array size calculated explicity but must match string length
With the array, it is like producing a pointer for each letter in the string and placing all the pointers in an array.
Yeah, what I meant was the a pointer has the address as well as the number of memory locations following that address that belong to the pointer, while an address is just an address without the reserved memory information. It was this extra information that the compiler could not match up to with the argument that was declared as a pointer.
Oh really? I always understood that a pointer was just an address, and nothing more. Really that is all I as a programmer should have to know anyway. What the compiler does internally shouldn't be generating warnings on perfectly legal code. But what do I know? I'm a rank newb at C again.
Nope. That's the reason you don't just have a single pointer for everything and why pointers have different data types like int pointers, char pointers, float pointers, double pointers THe data type tells the pointer how much memory is associated with it (the same number of bytes associated with the data type).
It is more important for commands for real C++ like new and delete which reserve areas of memory based for the pointer they are given.
I *think*. It's been a while since anything substantial in C/C++. Try it out. I could it look it up in my book, but it's like 4 feet away from me. Compared to declaring the variable and then making a pointer to it, tHe difference is that you only have a pointer to refer to the string and no variable name.
It would probably cause a warning because the datatypes are different/unexpected even though the information carried is the same. (But I think a compiler might reject this outright.)
EDIT:
Code:
char senpoint[] = "dsPIC 30F4013"
//is the same as
char *senpoint[] = "dsPIC 30F4013"
Because an array of chars, ints, or anything else is actually a pointer to the first character of the array (with some additional data about the number of elements in the array which are arranged consecutively in memory after the pointer), rather than an array of chars, int, or other regular variable type. That is why you can go
Code:
char sentence1[] = "dsPIC 30F4013 ";
and not have
Code:
lcd_string(sentence1);
complain that sentence1 is not a pointer. Just thought I'd let you know in case you accidentally left out the * in the array declaration and were suprised that it worked.
The reason it warns on lcd_string(&sentence1); is because the & is being used as the address of operator. So when you type &sentence1 you are saying the Address of the pointersentence1. Essentially you are giving a pointer to a pointer so the compiler balks because your lcd_string routine wants the actual pointer.
The reason lcd_string(&sentence1[0]) works is because sentence1[0] returns the character at index 0 in the array sentence1. Adding the & just returns the address of character at index 0 which is at the start of the array sentence1 so we end up with a pointer to the array sentence1.
The reason it warns on lcd_string(&sentence1); is because the & is being used as the address of operator. So when you type &sentence1 you are saying the Address of the pointersentence1. Essentially you are giving a pointer to a pointer so the compiler balks because your lcd_string routine wants the actual pointer.
The reason it warns on lcd_string(&sentence1); is because the & is being used as the address of operator. So when you type &sentence1 you are saying the Address of the pointersentence1. Essentially you are giving a pointer to a pointer so the compiler balks because your lcd_string routine wants the actual pointer.
The reason lcd_string(&sentence1[0]) works is because sentence1[0] returns the character at index 0 in the array sentence1. Adding the & just returns the address of character at index 0 which is at the start of the array sentence1 so we end up with a pointer to the array sentence1.
I think it is the language which has been confounding you If, instead, you say 'the name of the array is a pointer to the array,' rather than the array is a pointer. IE: 'array' contains the address of 'array[7]'
I think it is the language which has been confounding you If, instead, you say 'the name of the array is a pointer to the array,' rather than the array is a pointer. IE: 'array' contains the address of 'array[7]'
I knew you and dknguyen both got it, but in dknguyen's post, he stated his understanding, which isn't quite correct in terms of the language he used, but which I'm he understands the meaning of.
Handles (pointers to pointers) are quite common when dealing with an OS which dynamically assigns memory and I think pointers and their arithmetic are the most difficult parts for anyone learning C; they are also one of the most useful abstractions in C.
BTW I'm watching what you're doing with these dsPICs, since I'll be spending some time with them in the not too distant future, so thanks for blazing the trail!