By: Charlie Burnes (charlie.burnes.delete@this.no-spam.com), May 22, 2022 5:34 pm
Room: Moderated Discussions
That is an interesting dilemma. Thank you for explaining it. I now understand your point that there are pros and cons to each approach. I personally prefer simpler looking code so I would only use the unaligned variant and take a silent performance hit when data is unaligned. Surely there must be a tool to find unaligned loads and stores. A tool could put a few instructions after each load and store to test if the data address is aligned or it could substitute the aligned variants and catch the runtime faults. A quick Google search found this:
To catch these sorts of errors at runtime, use "-fsanitize=undefined". Tested on gcc v9.3 and clang v10.
Computers are extremely fast nowadays and always have idle CPU cores lying around doing nothing. The IDE should compile and run the code as you are typing it and display the unaligned loads and stores in a different color or mark them in some other way. Someone probably already thought of this idea and made a free extension for VS Code or some other IDE that does this.
To catch these sorts of errors at runtime, use "-fsanitize=undefined". Tested on gcc v9.3 and clang v10.
Computers are extremely fast nowadays and always have idle CPU cores lying around doing nothing. The IDE should compile and run the code as you are typing it and display the unaligned loads and stores in a different color or mark them in some other way. Someone probably already thought of this idea and made a free extension for VS Code or some other IDE that does this.