Vintage code
-
A colleague of me retired and his code should be supported. Its old C code from an embedded system that has been ported from assembly.
BYTE Scan1, Scan2, Scan3, Scan4; ... Err = ScanFunction(&Scan1);
That doesn't seems to be so bad, until i saw the Function declaration int ScanFunction(unsigned long* pScan); Later the data from the Scan bytes where placed in a long to work with the correct long value. To be sure it would work even after changes a comment has been placed before the byte declaration
/*--------please keep the order of the following bytes as it is. !!!!!!!!!*/ BYTE Scan1, Scan2, Scan3, Scan4
codito ergo sum
-
A colleague of me retired and his code should be supported. Its old C code from an embedded system that has been ported from assembly.
BYTE Scan1, Scan2, Scan3, Scan4; ... Err = ScanFunction(&Scan1);
That doesn't seems to be so bad, until i saw the Function declaration int ScanFunction(unsigned long* pScan); Later the data from the Scan bytes where placed in a long to work with the correct long value. To be sure it would work even after changes a comment has been placed before the byte declaration
/*--------please keep the order of the following bytes as it is. !!!!!!!!!*/ BYTE Scan1, Scan2, Scan3, Scan4
codito ergo sum
Makes perfect since to me! ;) (Old C programmer) I never liked tricks like that, but they do work in C. I would never recommend doing it though, as there are other ways to accomplish the same task. The only reason, I can think of, for ever doing something like this would be to reduce code, because you were limited by available memory. I have seen cases where adding any new code would have variables stepping on each other. Ok |--->...<---| Opps! |---->...| |...<----|
INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
-
A colleague of me retired and his code should be supported. Its old C code from an embedded system that has been ported from assembly.
BYTE Scan1, Scan2, Scan3, Scan4; ... Err = ScanFunction(&Scan1);
That doesn't seems to be so bad, until i saw the Function declaration int ScanFunction(unsigned long* pScan); Later the data from the Scan bytes where placed in a long to work with the correct long value. To be sure it would work even after changes a comment has been placed before the byte declaration
/*--------please keep the order of the following bytes as it is. !!!!!!!!!*/ BYTE Scan1, Scan2, Scan3, Scan4
codito ergo sum
hmm. that's strange. i've always seen it done like this:
BYTE Scan[4];
ulong *v = (ulong *)&Scan[0];
...Err = ScanFunction(v);
much safer.
image processing toolkits | batch image processing | blogging
-
A colleague of me retired and his code should be supported. Its old C code from an embedded system that has been ported from assembly.
BYTE Scan1, Scan2, Scan3, Scan4; ... Err = ScanFunction(&Scan1);
That doesn't seems to be so bad, until i saw the Function declaration int ScanFunction(unsigned long* pScan); Later the data from the Scan bytes where placed in a long to work with the correct long value. To be sure it would work even after changes a comment has been placed before the byte declaration
/*--------please keep the order of the following bytes as it is. !!!!!!!!!*/ BYTE Scan1, Scan2, Scan3, Scan4
codito ergo sum
Would be better to encapsulate those 4 bytes in a struct :)
**
xacc.ide-0.2.0.57 - now with C# 2.0 parser and seamless VS2005 solution support!
**
-
A colleague of me retired and his code should be supported. Its old C code from an embedded system that has been ported from assembly.
BYTE Scan1, Scan2, Scan3, Scan4; ... Err = ScanFunction(&Scan1);
That doesn't seems to be so bad, until i saw the Function declaration int ScanFunction(unsigned long* pScan); Later the data from the Scan bytes where placed in a long to work with the correct long value. To be sure it would work even after changes a comment has been placed before the byte declaration
/*--------please keep the order of the following bytes as it is. !!!!!!!!!*/ BYTE Scan1, Scan2, Scan3, Scan4
codito ergo sum
I'd do it like this:
union Data
{
unsigned long longVal;
BYTE asBytes[4];
};
Data d;
Err = ScanFunction(&d.longVal);Steve
-
A colleague of me retired and his code should be supported. Its old C code from an embedded system that has been ported from assembly.
BYTE Scan1, Scan2, Scan3, Scan4; ... Err = ScanFunction(&Scan1);
That doesn't seems to be so bad, until i saw the Function declaration int ScanFunction(unsigned long* pScan); Later the data from the Scan bytes where placed in a long to work with the correct long value. To be sure it would work even after changes a comment has been placed before the byte declaration
/*--------please keep the order of the following bytes as it is. !!!!!!!!!*/ BYTE Scan1, Scan2, Scan3, Scan4
codito ergo sum
I had a similiar situation occur, albeit in Fortran; a variable was declared as a byte, but received as a long... Took me a while to find out what was overwriting my data in the calling routine. The overwritten data was fixed values that shouldn't change! Tim
-
hmm. that's strange. i've always seen it done like this:
BYTE Scan[4];
ulong *v = (ulong *)&Scan[0];
...Err = ScanFunction(v);
much safer.
image processing toolkits | batch image processing | blogging
That may end up in a crash-boom-bang on hardware architectures which do not allow accessing words overlapping word boundaries. You'd have to use a union or #pragma (or something similar) to force alignment on the byte array.
-
That may end up in a crash-boom-bang on hardware architectures which do not allow accessing words overlapping word boundaries. You'd have to use a union or #pragma (or something similar) to force alignment on the byte array.
Joergen Sigvardsson wrote:
on hardware architectures which do not allow accessing words overlapping word boundaries
yeah like i got the time to worry about writing architecture-agnostic code :rolleyes: Windows on Intel is my target.
image processing toolkits | batch image processing | blogging
-
Joergen Sigvardsson wrote:
on hardware architectures which do not allow accessing words overlapping word boundaries
yeah like i got the time to worry about writing architecture-agnostic code :rolleyes: Windows on Intel is my target.
image processing toolkits | batch image processing | blogging
Yeah, but the other guy might be on some other platform. :) (And no, I couldn't care less about other platforms either, as the stuff I write here will never run on anything but Wintel)
-
A colleague of me retired and his code should be supported. Its old C code from an embedded system that has been ported from assembly.
BYTE Scan1, Scan2, Scan3, Scan4; ... Err = ScanFunction(&Scan1);
That doesn't seems to be so bad, until i saw the Function declaration int ScanFunction(unsigned long* pScan); Later the data from the Scan bytes where placed in a long to work with the correct long value. To be sure it would work even after changes a comment has been placed before the byte declaration
/*--------please keep the order of the following bytes as it is. !!!!!!!!!*/ BYTE Scan1, Scan2, Scan3, Scan4
codito ergo sum
I would have done it in binary like so:
1101010101001101110010100111010101010011011100101001
1010101010011011100101001110101010100110111001010010
0101010100110111001010011101010101001101110010100110
1101010101001101110010100111010101010011011100100101
1101010101001101110010100111010101010011011100101001That way there's less confusion
There are 10 types of people in the world, those who understand binary and those who dont.