address alignment

Programming, for all ages and all languages.
Post Reply
User avatar
devel
Member
Member
Posts: 62
Joined: Wed Nov 28, 2007 4:15 am
Contact:

address alignment

Post by devel »

Hi,

might be a newbie question but how to locate a 6 bytes structure at an odd word address i.e.
address mod 4 equals to 2? An example in C would be very helpful, thnx.

regards,
devel.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

I am confused by your question. Do you want to know how to find a 6-byte structure or are you wondering about its location relative to an 'odd' linear address?
User avatar
devel
Member
Member
Posts: 62
Joined: Wed Nov 28, 2007 4:15 am
Contact:

Post by devel »

01000101 wrote:I am confused by your question. Do you want to know how to find a 6-byte structure or are you wondering about its location relative to an 'odd' linear address?
how to put 6bytes structure at an odd word address.
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Post by cyr1x »

Code: Select all

 memcpy(ptr-(ptr%4), ptr, lenght); 
I think this should work.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

Add a 2 byte word to the beginning of the structure, and put it at a normal address -- then pass the pointer to the second entry in the structure.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Re: address alignment

Post by os64dev »

devel wrote:how to locate a 6 bytes structure at an odd word address i.e.
address mod 4 equals to 2? An example in C would be very helpful, thnx.

Code: Select all

struct pseudo_ptr {
    unsigned short dummy;
    unsigned short segment:
    unsigned long  address;
};
an example where it is used. struct needs to be packed btw.
Author of COBOS
Post Reply