How 'bout this? I'm not sure if I understood the point but I think I did:
Code:
#include <stdio.h>
#include <linux/types.h>
typedef __s16 dword;
struct input {
char A;
char B;
};
union twobytes {
struct input this;
dword that;
};
dword pack (char a, char b) {
union twobytes example;
example.this.A=a;
example.this.B=b;
return example.that;
}
int main() {
char a=0, b=1;
printf("%d\n",pack(a,b));
return 0;
}
answer: 256 (which makes sense to me). I think the arguments are in the reverse order from the OP.
ps. Is there a more portable source of specific bitsized datatypes than this? I just dug it out of "usr/include" because I didn't want to rely on
short.