We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
so lots of threads on this forum say you must not care about how the compiler puts things into structures with alignment and padding and stuff
then we look at example code with structures used to access registers like in cmsis
who is right and what is safe?
Your view is rather extreme. Yes, structures can have non-portable alignment, padding, endianness. But when portability is not an issue, you can use structures to your benefit. That's the case with CMSIS: the library targets a specific CPU family, it also uses non-standard compiler features to make it work (hence, it works with a limited set of compilers.) I believe structures are often used for MCU register definitions. Again, those are MCU-specific and probably use non-standard compiler extensions. No portability here either. So it's portability vs. compiler-specific features. It takes some experience to find the right balance.