Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionvoid pointer? Pin
sam_psycho30-Jul-09 6:21
sam_psycho30-Jul-09 6:21 
AnswerRe: void pointer? Pin
molesworth30-Jul-09 7:49
molesworth30-Jul-09 7:49 
GeneralRe: void pointer? Pin
sam_psycho30-Jul-09 8:06
sam_psycho30-Jul-09 8:06 
GeneralRe: void pointer? [modified] Pin
Joe Woodbury30-Jul-09 8:20
professionalJoe Woodbury30-Jul-09 8:20 
GeneralRe: void pointer? Pin
sam_psycho30-Jul-09 8:30
sam_psycho30-Jul-09 8:30 
GeneralRe: void pointer? Pin
Joe Woodbury30-Jul-09 8:35
professionalJoe Woodbury30-Jul-09 8:35 
GeneralRe: void pointer? Pin
sam_psycho30-Jul-09 9:01
sam_psycho30-Jul-09 9:01 
GeneralRe: void pointer? Pin
Joe Woodbury30-Jul-09 9:45
professionalJoe Woodbury30-Jul-09 9:45 
I don't understand why you are using a void*. It has no concept of size of what it's pointing to. You are removing type safety for no reason.

That said, when you increment do arithmetic on a pointer, that arithmetic is done according to the size of the object pointed to by that pointer. In this case you are casting ptr to an (int*). Therefore, you only need to increment ptr by 1 to take you to the next position. (As an aside, (int*)ptr += 1; will not compile on many compilers--you would have to have ptr = (int*)ptr + 1;

Two other points:

You don't need to cast arr to a void*, that cast is automatic.

You have an off by one error; you have four items in your array, but you only go through the loop three times.

You simply shouldn't be using a void* in a case like this. It's an extremely bad idea. It would be better to use arr[] directly or if you must use a pointer, use an int*.
GeneralRe: void pointer? Pin
sam_psycho30-Jul-09 16:43
sam_psycho30-Jul-09 16:43 
GeneralRe: void pointer? Pin
Joe Woodbury30-Jul-09 17:04
professionalJoe Woodbury30-Jul-09 17:04 
QuestionC++ Excel Automation -- assign array to range Pin
MattPugsley30-Jul-09 5:45
MattPugsley30-Jul-09 5:45 
GeneralRe: C++ Excel Automation -- assign array to range -- mostly working now Pin
MattPugsley30-Jul-09 10:12
MattPugsley30-Jul-09 10:12 
GeneralRe: C++ Excel Automation -- assign array to range -- mostly working now Pin
Le@rner31-Aug-10 23:32
Le@rner31-Aug-10 23:32 
QuestionCan we change pointer type in the run time? Pin
THAQCD30-Jul-09 3:45
THAQCD30-Jul-09 3:45 
AnswerRe: Can we change pointer type in the run time? Pin
Code-o-mat30-Jul-09 4:04
Code-o-mat30-Jul-09 4:04 
GeneralRe: Can we change pointer type in the run time? Pin
THAQCD30-Jul-09 8:21
THAQCD30-Jul-09 8:21 
GeneralRe: Can we change pointer type in the run time? Pin
Code-o-mat30-Jul-09 8:28
Code-o-mat30-Jul-09 8:28 
AnswerRe: Can we change pointer type in the run time? Pin
MattPugsley30-Jul-09 7:51
MattPugsley30-Jul-09 7:51 
GeneralRe: Can we change pointer type in the run time? Pin
THAQCD30-Jul-09 8:32
THAQCD30-Jul-09 8:32 
QuestionHow to avoid a Global Variable Pin
Madhu_Rani30-Jul-09 3:36
Madhu_Rani30-Jul-09 3:36 
AnswerRe: How to avoid a Global Variable Pin
Chris Losinger30-Jul-09 5:12
professionalChris Losinger30-Jul-09 5:12 
AnswerRe: How to avoid a Global Variable Pin
Rick York30-Jul-09 6:07
mveRick York30-Jul-09 6:07 
GeneralRe: How to avoid a Global Variable Pin
Madhu_Rani30-Jul-09 20:04
Madhu_Rani30-Jul-09 20:04 
GeneralRe: How to avoid a Global Variable Pin
Madhu_Rani30-Jul-09 20:36
Madhu_Rani30-Jul-09 20:36 
Questionfwrite for unicode characters... Pin
Rakesh530-Jul-09 1:57
Rakesh530-Jul-09 1:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.