Hi I have some problems with struct inside a union This is my code.
union{ unsigned char id_byte[2]; struct { unsigned char DLC:4; unsigned char RTR:1; unsigned int identifier:11; }del_element; }can_descriptor;
union{ unsigned char id_byte[2]; struct { unsigned int identifier:11; unsigned char DLC:4; unsigned char RTR:1; }del_element; }can_descriptor;
year ok. yes as small as passebel, no time to waste. You say that i shoud use mask and shift? dose't it give more code? Soren
"You say that i shoud use mask and shift? dose't it give more code?" Try re-reading the previous posts! Here's a reminder of what's been said so far: "many compilers generate poor code for bitfields. It's more portable and often more efficient just to use the & and | operators directly." "I don't think there's any reason to believe that bitfields will give you (significantly) better code than shifts and masks and some bitfield implementations are notoriously inefficient - so shifts and masks can actually be better!" "[shift & mask] is probably how the compiler actually implements the bitfields!" That should answer your question! And again, shifts & masks are portable; bitfields are not.
thanks i try that. soren