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.
Hello Forum, I want to compose two int variables, which contains the LSW and MSW, respective, into one unsigned long variable. The following code does the right thing:
int lo, hi; unsigned long longvar; longvar = (unsigned long) (unsigned int) hi << 16 | (unsigned long) (unsigned int) lo;
longvar.msw = hi; longvar.lsw = lo;
Hello, sorry - I've said "thanks" somewhere in the thread to say "thanks" to all posters, regardless I used they suggestions or not. The reason why I wont use unions is the already meanted little/big endian problem. I use a solution that depends on the ordering - that's ok because the ordering doesn't change. In general, I expect the ordering wont change at runtime. Therefore, to get the right solution, the ordering must be known at compiletime. The reason why I'd asked here is that I supposed there is a solution that uses the same .c input, but gets different output, based on the compilers knowledge on byte/word ordering; without forcing me to know about the ordering. As a conclusion, I'm still using the solution that depends on the ordering... - Peter Sorry if there is any strange language, but I'm not a native speaker.