We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I observed a strange behaviour (for me only) of void pointer. I wrote a code to access an integer through void pointer as below:
void *ptr; int a[2] = {1,2};
ptr = (int *)&a; ptr++; // This is giving error: Unknown Size
Why the above increment statement is giving error as i already cast the pointer to int type ?
Can anybody help me in understanding this ?
Karthik K.
((int *)ptr)++;
Jon
Jon, I was trying to encourage a good style of programming in C, and you ruined it by showing an easy workaround :-) Ah well, let him learn the hard way.
Thanks to all for guiding me... So if i understood correctly, then i can say that whenever i need to access void pointer, i have to cast it to proper type.
Well, I want to improve my C knowledge. Can anyone suggest a way... ?
warning: #1441-D: nonstandard cast on lvalue
Is that ok?
get it done by somebody;
ya ok,
"I want to improve my C knowledge. Can anyone suggest a way... ?"
Do a 'C' programming course.
Get a decent 'C' textbook.
Probably best to learn the language on a PC or similar; then, once you know the language, you can learn how to apply it to microntrollers...
Thanks Neil for your suggestion. I know the basic of C, but some miscellaneous concept like void pointer, null pointer, dangling pointer,etc.. will be explored in most of the book. Generally C book gives the basic programming guide, not the in depth knowledge. Or may be but i am not aware of such book.
If any one have idea then please let me know.
Thanks Neil for your suggestion. I know the basic of C, but some miscellaneous concept like void pointer, null pointer, dangling pointer,etc.. will not be explored in most of the book. Generally C book gives the basic programming guide, not the in depth knowledge. Or may be but i am not aware of such book.
ANDY, that was a nice answer, applauds, is there a reason to learn C, and THEn apply to ucontrollers,
certainly there should be other ways,
andy, do u take classes for C? got to start from 'c'ing c..
is there a reason to learn C, and THEn apply to ucontrollers, certainly there should be other ways,
There are as many 'ways' as there are peaches in Gaffney, but "to learn C, and THEn apply to ucontrollers" is the best and - surprise - fastest.
Erik
"((int *)ptr)++;
Is that ok?"
Although some compilers accept it, it's really an error because the postfix increment operator requires a modifiable lvalue and a cast does not yield an lvalue.
What does work on all compilers is:
ptr = ((int *)ptr) + 1;
Thats absolutely true ..!!
You are htere absolutely Fastest, :)
Have you checked, http://www.keil.com/forum/docs/thread8679.asp