Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Now they are different types you can still pass by value, but trying to assign a value of one type to a variable of the other will cause an error. Pretty neat trick actually. And if you are using C99, you can just use compound literals for these types, which makes it even easier to use them.
nullplan wrote:You should not. This structure has the wrong alignment (16 bits instead of 32).
I find it unlikely that alignment is going to be a problem with these structures since they are usually "allocated" using a page allocator (and pages are 4K aligned).
But for what's it's worth, one can easily force the alignment to 32 bits with __attribute__ ((aligned(4)).
That said, I find that using uint32_t (wrapped in a structure like Linux does or not) is much more straightforward.
aphexia wrote:Is it because the cpu expects a continuous 32 bit number, and so the entire 4 bytes should be reversed?
The nice thing about just using 32-bit integers is that you don't need to worry about stuff like that.
kzinti wrote:I find it unlikely that alignment is going to be a problem with these structures since they are usually "allocated" using a page allocator (and pages are 4K aligned).
True, the approach is better suited to the GDT or IDT.
kzinti wrote:But for what's it's worth, one can easily force the alignment to 32 bits with __attribute__ ((aligned(4)).
You can, but why would you want to? In all seriousness, just using a 32-bit integer is going to be way easier than using a structure with multiple parts for no reason.