Making bootsector for USB pen

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.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Making bootsector for USB pen

Post by Korona »

kmcguire wrote:
Korona wrote:I don't know if that causes any problem in this case but generally structures that the compiler must not align or reorganize should be marked with __attribute((__packed__)).
Structures that have member fields that you do not want padded to maintain alignment on word boundaries need to use the __attribute__((__packed__)) expression. The C compiler should never reorganize the members of a structure! The padding increases the performance of data access (if you have ever noticed inside the manuals for a processor's instruction set it will hint to performance decreases on unaligned memory accesses for some stuff).

The alignment of the structure it's self comes from it's creation. Such that if you create the structure as a local variable then it is automatically aligned by the stack's word size. While, if you create the structure using a pointer, then the structure may or may not be aligned no matter if you used the __packed__ attribute or not.
Yes, of course the __packed__ attribute only affects internal alignments. Are you sure that the C compiler is not allowed to reorganize the members of the structure? I don't think that is part of the ANSI C standard though I did not check that.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
Post Reply