What, exactly, does not work? How, exactly, does it fail? Do you understand the issues of data alignment - and, hence, why compilers often add padding to structures...?
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
How, exactly, do you know that? What, exactly, does it do? Again: Do you understand the issues of data alignment - and, hence, why compilers often add padding to structures...?
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Posted on May 17, 2011 at 14:30 I expect from this line is to cast the sizeof(hdr) bytes from the start of usart_buffer to the structure hdr, but it does not do ! hdr = ( header1*)usart_buffer or at least give hdr and usart_buffer the same address location , but it does not ! what did I miss there ? Thank you for your responses .
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Why do you have to make it so hard to wring the information out of you?
Just saying ''it doesn't work'' or ''it's wrong'' is virtually useless - it's like saying, ''my car doesn't work - what's wrong with it?'' You need to explain precisely how it's wrong, or how it doesn't work''I cant see the right result'' So what result, exactly, do you see? Have you compared the actual result, and the expected result, and thought about the difference - and how you could explain it?Data Aligbnment refers to the requirement that most processors have for data items bigger than 1 byte to start on certain addresses; eg, 2-byte objects need to start on an even address, so that they can be fetched in a single operation; 4-byte objects need to start on a 4-byte boundary, so that they can be fetched in a single operation; But 1-byte objects can start on any arbitrary address. It should be obvious that this is going to cause issues if you try to mess with pointers where the target objects have different alignment requirements...
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Well, it might just happen not to fail in this case - but you really mustn't make a habit of casting pointers like this! If you have a pointer to some unaligned item, and cast it to something that needs to be aligned, then your program will crash.
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.