This site is no longer active and is available for archival purposes only. Registration and login is disabled.

datatype misalignment


Re: datatype misalignment

Postby simonjacobs » Jan 6, 2002 @ 10:49am

User avatar
simonjacobs
pm Insider
 
Posts: 311
Joined: Nov 27, 2001 @ 4:51pm
Location: London, UK


Re: datatype misalignment

Postby R0B » Jan 6, 2002 @ 10:53am

"1011001010 NNNNNNNNNNOOOOOOOOOOOOOOOO!!!!!!" -Bender
User avatar
R0B
got muffins?
 
Posts: 1894
Joined: Jun 22, 2001 @ 12:04pm


Re: datatype misalignment

Postby simonjacobs » Jan 6, 2002 @ 10:54am

User avatar
simonjacobs
pm Insider
 
Posts: 311
Joined: Nov 27, 2001 @ 4:51pm
Location: London, UK


Re: datatype misalignment

Postby R0B » Jan 6, 2002 @ 11:04am

"1011001010 NNNNNNNNNNOOOOOOOOOOOOOOOO!!!!!!" -Bender
User avatar
R0B
got muffins?
 
Posts: 1894
Joined: Jun 22, 2001 @ 12:04pm


Re: datatype misalignment

Postby R0B » Jan 6, 2002 @ 2:01pm

"1011001010 NNNNNNNNNNOOOOOOOOOOOOOOOO!!!!!!" -Bender
User avatar
R0B
got muffins?
 
Posts: 1894
Joined: Jun 22, 2001 @ 12:04pm


Re: datatype misalignment

Postby simonjacobs » Jan 6, 2002 @ 2:16pm

User avatar
simonjacobs
pm Insider
 
Posts: 311
Joined: Nov 27, 2001 @ 4:51pm
Location: London, UK


Re: datatype misalignment

Postby Digby » Jan 6, 2002 @ 6:18pm

Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: datatype misalignment

Postby Dan East » Jan 6, 2002 @ 7:27pm

User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Re: datatype misalignment

Postby Dan East » Jan 6, 2002 @ 8:00pm

Here is a specific example from the pWolf source. This appears to be exactly the same problem you're encountering, except the code is wrapped in a define. The original code is commented out. My CE alternative is the following 3 lines:<br>[fixed]<br>//Dan East: Alignment problems here:<br>//length = *( ( unsigned short * ) demoptr )++;<br>length = ( * ( ( unsigned char * ) demoptr ) ++ );<br>length |= ( * ( ( unsigned char * ) demoptr ) ++ )<<8;<br>demoptr++;<br>[/fixed]<br><br>Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Re: datatype misalignment

Postby Dan East » Jan 6, 2002 @ 8:06pm

Another alignment fix from pWolf, again, almost the exact same thing as the problem you're encountering. This differs from the above example in that it is a 32 bit int instead of a word. "source" is an unsigned char.<br>[fixed]<br>#ifndef _WIN32_WCE<br>expanded = *( long * )source;<br>source += 4; // skip over length<br>#else<br>//Dan East: Workaround for alignment issues<br>expanded = *source++;<br>expanded |= ( *source++ ) << 8;<br>expanded |= ( *source++ ) << 16;<br>expanded |= ( *source++ ) << 24;<br>#endif<br>[/fixed]<br><br>Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Re: datatype misalignment

Postby R0B » Jan 6, 2002 @ 8:11pm

Thanks Dan, I will try that now.  Digby, I respect your programing skill and knowledge, but I think that you should relax.  I have tried everything with that "__unaligned" definition, and it won't help in this situation.  I just happedened to post an example where I tried casting __unaligned to see if that would help.  But, it failed to change the code at all.  By the way, you should have used muffins.  And, they don't go on the hood of the car, they go in the trunck.
"1011001010 NNNNNNNNNNOOOOOOOOOOOOOOOO!!!!!!" -Bender
User avatar
R0B
got muffins?
 
Posts: 1894
Joined: Jun 22, 2001 @ 12:04pm


Re: datatype misalignment

Postby R0B » Jan 6, 2002 @ 9:16pm

Ok, I get what you are saying Dan.  Your example is just the reverse of mine.  I have to store the value or the ULONG in *p a byte *.  So, here is my thought.<br><br>*p ++ = (byte)wadfiles[i]->filesize; <br>*p ++ = (byte)wadfiles[i]->filesize <<8;<br>p++;<br><br>Only that won't work because *p ++ = (byte)wadfiles[i]->filesize; would try to store everything in *p, not just the lower byte.  But wait, wouldn't I have to do that four times, since p is a byte, but filesize is a ULONG.  Also, p points to the address of a unsigned char[500].  Would that mess it up at all.  I think that we are getting somewhere, but I could still use more help.<br><br>
"1011001010 NNNNNNNNNNOOOOOOOOOOOOOOOO!!!!!!" -Bender
User avatar
R0B
got muffins?
 
Posts: 1894
Joined: Jun 22, 2001 @ 12:04pm


Re: datatype misalignment

Postby simonjacobs » Jan 6, 2002 @ 9:27pm

Rob: Does this work:<br><br>unsigned char *p = something;<br>ULONG temp = wadfiles->filesize;<br><br>memcpy(p, &temp, 4);<br><br>
User avatar
simonjacobs
pm Insider
 
Posts: 311
Joined: Nov 27, 2001 @ 4:51pm
Location: London, UK


Re: datatype misalignment

Postby simonjacobs » Jan 6, 2002 @ 9:28pm

sorry, i'm tired, what i meant was:<br><br>memcpy(p,&wadfiles->filesize,4);<br><br>
User avatar
simonjacobs
pm Insider
 
Posts: 311
Joined: Nov 27, 2001 @ 4:51pm
Location: London, UK


Re: datatype misalignment

Postby simonjacobs » Jan 6, 2002 @ 9:30pm

my theory is that memcpy will take care of the alignment problem :)<br><br>i am probably wrong as usual.<br><br>it WOULD be funny if all this hassle could have been avoided with a single memcpy command though!
User avatar
simonjacobs
pm Insider
 
Posts: 311
Joined: Nov 27, 2001 @ 4:51pm
Location: London, UK


PreviousNext

Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron