You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/03/25 12:09:40 UTC

[GitHub] [incubator-nuttx] gustavonihei edited a comment on pull request #3169: arch/stm32h7 - Fix compiler warnings and error in stm32_dma.c

gustavonihei edited a comment on pull request #3169:
URL: https://github.com/apache/incubator-nuttx/pull/3169#issuecomment-806616431


   > @hartmannathan
   > 
   > I have seen a lot of fixes for this class of error using different approaches. @patacongo mentioned the conical form as you have used here in. I was trying to discern the correct pattern and if it is divided on a common OS and arch driver boundary or are we just not being consistent and should ask for changes on PRs.
   > 
   > To that end, do you feel we should add an explicit `#include <inttypes.h>` to these files?
   
   I believe this is not related to having a pattern across the OS, is more like standards-related.
   If you use the native types (int, long, short...) than the recommended is to use the conversion specifiers from the ' fprintf' documentation:
   https://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html
   
   If you use the fixed-width integer types from `stdint.h` (uint32_t, int32_t, int8_t...), then it is recommended to use the conversion specifiers from `inttypes.h`. By using this approach you abstract implementation details and the code will be portable across different architectures.
   https://en.cppreference.com/w/c/types/integer
   
   So, if you keep using `%ld` for `int32_t` on an **armv7-a** machine, it is correct from the compiler's point of view. But it is not correct regarding abstraction, since you are leaking machine implementation details to your application/driver.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org