[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] alignment problems
From: |
Bartlomiej Wicher |
Subject: |
Re: [lwip-users] alignment problems |
Date: |
Thu, 08 Nov 2007 16:50:44 +0100 |
User-agent: |
Opera Mail/9.24 (Win32) |
Of course, you are right, I can address them indivudually:
char foo[5] = {0x12, 0x34, 0x56, 0x78, 0};
x = foo[0]; //x = 0x12;
x = foo[1]; //x = 0x34;
x = *(foo); //x = 0x12
x = *(foo+1); //x = 0x34;
I've just checked the way how compiler deals with that - it doubles the
address of
an array and it's content:
char foo[5] = {0x12, 0x34, 0x56, 0x78, 0}; //address of foo is 0x2f91
char *xP;
xP = &foo[0]; //xP points to 0x5f22 (I see it in debugger) but it's value
is 0x12
xP = &foo[1]; //xP points to 0x5f23 but it's value is 0x34
I don't know how the compiler deals with overwriting the memory (maybe
debugger shows some dummy values...).
The thing is that physically foo[0] and foo[1] have exactly the same
address (0x2f91 in that case) and I'm not sure how it could influence
lwIP. I've just checked how conversion from int* to char* works:
int boo[5] = {0x12, 0x34, 0x56, 0x78, 0}; //address 0x2f8c
char *xP;
xP = (char *)&boo[0]; //xP points to 0x5f18, value is 0x12
xP = (char *)&boo[1]; //xP points to 0x5f1a, value is 0x34
xP = (char *)&boo[2]; //xP points to 0x5f1c, value is 0x56
xP = (char *)&boo[3]; //xP points to 0x5f1e, value is 0x78
Well, it seems to work fine, but I'm not absolutely sure if that behaviour
is standard...Sorry for misunderstandings.
I'll set alignment to 2 and keep working with it. Right now I have some
problems with memp_malloc - program crashes on that function...
Thank you for your response
I've never seen a compiler that supported 8 bit chars that couldn't
address each of them individually. The processor may not address them
individually, but you should be able to access each char independently
at the higher level. That's what higher level languages do - hide the
details of the hardware.
Access to individual char values on a word-based bus may result in the
compiler generating a read+shift or read+mask, but you still can
typically load/store even and odd addressed characters at the 'C' level.
-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf
Of Kieran Mansley
Sent: Thursday, November 08, 2007 6:27 AM
To: Mailing list for lwIP users
Subject: Re: [lwip-users] alignment problems
On Thu, 2007-11-08 at 11:08 +0000, Jonathan Larmour wrote:
I'm concerned that you say that "two addresses" are only used with
long, and one for both char and int. Does this mean that for:
char foo[4];
that: &foo[0] == &foo[1] ?
If that is the case, I think you may have an uphill struggle.
Yeah, that confused me. Sounds like it would be sensible to think of it
as having 16-bit bytes rather than worrying about the word size. If
that's the case I think there may be problems for you in lwIP where
we've confused bytes with octets (i.e. 8 bits).
Kieran
_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users
_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users
--
Bartlomiej Wicher
University of Southern Denmark
Odense, Denmark