We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a project where data is received to array a, reformatted to array b, then reformatted to array c. The arrays are different sizes. The process is relevant as different parts of array b are reformatted to array c at different times. There is a possibility that array a may overflow ever so slightly; however if it overflows into array c, it will not be a problem. The question is: can I 'trick' the linker to place array c immeddiately following array a in memory. Thanx, Erik
I thought you could do that with the compiler. I think checking "Keep variables in order" in the C51 dialog or ORDER on the C51 command line should do it. Of course you'd then need to define the three arrays in order in a C file, .e.g.
SomeType arrA[SOME_SIZE]; SomeType arrB[SOME_OTHER_SIZE]; SomeType arrC[SOME_DIFF_SIZE];
Or you could define the arrays within a struct, thus guaranteeing their order. Not sure what (if any) impact this may have on access efficiency - but I'm quite sure that you're fully capable of investigating that for yourself, if it's an issue! ;-)
The struct is a good idea but C does not guarantee that there won't be pad bytes added. In this case though I think the pad bytes wouldn't matter.
"C does not guarantee that there won't be pad bytes added" This is true; however, in this specific case, I don't think that Keil C51 ever adds padding bytes (there would be no reason to do so on an 8-bit processor). Generally, I think most compilers have an option to prevent the addition of padding bytes?
True, on an 8-bit machine without alignment considerations I'd agree with you. I just like to raise portability issues so we all remember what C guarantees. Yes most compilers offer some #pragma pack or __attribute__((packed)) option.