LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2011, 03:44 AM   #1
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Rep: Reputation: 15
Question assembly ,structure references to members! thanks


Code:
WNDCLASS struct
  style         DWORD
  lpfnWndProc   DWORD
...
WNDCLASS ends

.data?
stWndClass WNDCLASS <>
...
mov esi,offset stWndClass
mov eax,[esi+WNDCLASS.lpfnWndProc]

mov eax,[esi+stWndClass.lpfnWndProc]
if the address of stWndClass is 403000h, WHY it would be compile as
mov eax,[esi+403004] and the first one would be
mov eax,[esi+4] ? I know how to get the values 403004h and 4,but do not know why.thanks very much

Last edited by topheraholic; 07-09-2011 at 03:48 AM.
 
Old 07-09-2011, 04:33 AM   #2
axet
LQ Newbie
 
Registered: Feb 2009
Posts: 15

Rep: Reputation: 0
because you are reffering to second element and length of first is 4 bytes

change to:

stWndClass.style
 
Old 07-09-2011, 08:15 AM   #3
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep: Reputation: 15
i know 4, it is not the point! you did not get what i am saying! my point it why it is 304000h while the other is 4? why they are not both 4!?
 
Old 07-09-2011, 08:27 AM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by topheraholic View Post
i know 4, it is not the point! you did not get what i am saying! my point it why it is 304000h while the other is 4? why they are not both 4!?

WNDCLASS.lpfnWndProc
is the offset of lpfnWndProc within the definition of the struct, so it is 4, which is the offset of that member relative to the start of the struct.

stWndClass.lpfnWndProc
is the address of that member of that specific instance of the struct within memory.

Last edited by johnsfine; 07-09-2011 at 08:28 AM.
 
Old 07-09-2011, 08:41 AM   #5
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep: Reputation: 15
So why WNDCLASS.lpfnWndProc is not the address of WNDCLASS plus the offset of lpfnWndProc ?

and why stWndClass.lpfnWndProc is not the offset of lpfnWndProc within the definition of the struc,which it should be 4?

why stWndClass.lpfnWndProc is the address of that member in memory which WNDCLASS.lpfnWndProc is not?

i mean is it because stWNdClass is a sturcture variable? so it has a address in memory? but what does WNDCLASS? it is a structure,not a variable?so it is no address in memory? i am so comfused! thanks a lot!

Last edited by topheraholic; 07-09-2011 at 09:03 AM.
 
Old 07-09-2011, 11:10 AM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by topheraholic View Post
So why WNDCLASS.lpfnWndProc is not the address of WNDCLASS plus the offset of lpfnWndProc ?
You came near to answering your question yourself (see below).

WNDCLASS is not an object in memory. It has no address.

Quote:
is it because stWNdClass is a sturcture variable? so it has a address in memory?
Yes.

Quote:
WNDCLASS? it is a structure,not a variable?so it is no address in memory?
Right. A structure definition is not an object in memory and it has no address.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert directory structure from long file names in Linux to DOS 8.3 structure? manorina Linux - Software 5 09-12-2009 09:18 AM
Home Jail Folder Structure like Gobolinux Directory Structure luispt Linux - General 3 07-26-2008 06:46 PM
??Good C References Please?? InvisibleSniper Programming 9 10-28-2005 01:45 PM
references jenny_psion Programming 0 08-12-2003 03:06 AM
why compiler gives undefined references on static members??? Hano Programming 8 06-26-2002 11:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration