Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Could someone Reduce this code for me? Its only 4 lines.

Author
Message
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 9th Feb 2008 00:09
I was struggling with this - to get it to work - this code WORKS - but how would you reduce it to TWO lines versus four?



Thank you in Advance!

Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 9th Feb 2008 00:28
assuming variables lpItem1 and lpItem2 are not needed anywhere else.. try converting item + offset to "JFC_STRING*" instead of "unsigned int *" ... like: (ie: a quick quess, dunno if works)

JFC_STRING_Item1=(JFC_STRING*)((unsigned int)Item1 + p_lpOffset);
JFC_STRING_Item2=(JFC_STRING*)((unsigned int)Item2 + p_lpOffset);

may not need (unsigned int) type conversion... try:
JFC_STRING_Item1=(JFC_STRING*)(Item1 + p_lpOffset);
JFC_STRING_Item2=(JFC_STRING*)(Item2 + p_lpOffset);

Inspirational Music: Descent ][ Redbook Audio CD Soundtrack
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 9th Feb 2008 01:30 Edited at: 9th Feb 2008 02:49
I really appreciate the response.

I have tried:


But unknown to you - Item1 is a (void*) or void pointer.[edit] and the p_lpPointer is an address but is an unsigned int also - the name is misleading[/edit] This means the unsigned int like here is required to compile but gives undesired results:


So the code snippet I originally posted is the only one that works.

I have a sneaking suspicion I need a ** <----Indirect Pointer notation... but I can't figure out the syntax.

Basically, Item1 - is a pointer to a class, the offset is the position in this pointed to class - of a pointer ... to yet another class.

The code I posted originally - I swear it WORKS, but I'm doing two steps. It took many iterations to get it to work - but it works beautiful I swear. I just think the way I wrote it to finally work still is not "reduced" as much as it could be.

So I'm shooting for:


Note: ADDRESS_IN_MEM is the value INSIDE the Void* Item1 pointer.

NOTE: TODD - Your answer and my (prior to this post) previous attempts KEPT coming to the syntax you came up with. It seems correct when I read it to. But in the debugger - the only time I see the correct values of this "class" pointed to by a pointer in my Item1 "class" is with the syntax I posted above.

(I was iteratively trying things - 3rd evening trying to fix this flawed code... and I got it today when I came home...)

I think I forced the same functionality as a indirect pointer - or "A pointer that points to a pointer that points to my class" normally described as the ** operator. I dunno - I think I got lucky - I just think Its not as concise as it should be. I also think when someone gets it - somehow seeing the syntax will open a new level of pointer understanding for me (and hopefully others).

Thanx for giving it a honest go of it!
Jason

Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 9th Feb 2008 03:51 Edited at: 9th Feb 2008 03:54
lol ... i hear exactly what your talking about, ofcoarse I was giving a shot in the dark since I didnt have the rest of your code to look at.

doing stuff like ** is just levels of indirection of pointer management. Like you said, casting a (unsigned int) on a void*(Item1) is needed.

Im "guessing" now that p_lpOffset is a pointer also?? I'll guess Void * for it also for now.

[brain processing]
unsigned int *lpItem1=

(unsigned int *)((unsigned int)Item1 + p_lpOffset);
(unsigned int *)
((unsigned int) ((Void*) + (Void*)) );
casting two pointers into a (unsigned int) result,
once the (unsigned int) result is found,
cast it back to a (unsigned int *).

JFC_STRING_Item1=(JFC_STRING*)*lpItem1;

JFC_STRING_Item1=(JFC_STRING*)*(unsigned int *);
[/brain processing]

Ok, try:
JFC_STRING_Item1=(JFC_STRING*)*((unsigned int *)((unsigned int)Item1 + p_lpOffset));


edit: oh,,, lol I didnt read all of your post clearly... congrats!

Inspirational Music: Descent ][ Redbook Audio CD Soundtrack
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 9th Feb 2008 04:11
haha - Good POST! (Btw - name misleading again - p_lpOffset IS a unsigned int... but the name reflects what I'm trying to use it for - p_ = parameter to my function, lpOffset ... SHOULD mean its a long pointer ... but I meant it as "for pointer math" while I was hacking this together! (My Bad!)

I like the look of your "Ok Try"! ... Let Me try it!

WOO HOO!!!! YOU DID IT! CONGRATS TO YOU!!!!!!

THANX!

Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 9th Feb 2008 04:20
lol
I thought wrong at ((unsigned int) ((Void*) + (Void*)) );
I should of known something was fishy with only casting item1 as an unsigned int and not p_lpOffSet. So "assuming" can stear me wrong.

It just came down to plug n' play!

Inspirational Music: Descent ][ Redbook Audio CD Soundtrack
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 9th Feb 2008 04:55
haha... here is the finished code you helped me with:


Login to post a reply

Server time is: 2024-11-20 01:47:00
Your offset time is: 2024-11-20 01:47:00