SHIVAM DEOLANKAR commented on a discussion on cpukit/include/rtems/error.h: https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1069#note_143192 > -#define RTEMS_ERROR_ABORT (RTEMS_ERROR_ERRNO / 4) /* err is fatal; > panic */ > -#else > -#define RTEMS_ERROR_ERRNO (0x40000000) /* hi bit; use 'errno' */ > -#define RTEMS_ERROR_PANIC (0x20000000) /* err fatal; no return */ > -#define RTEMS_ERROR_ABORT (0x10000000) /* err is fatal; panic */ > -#endif > +/* > + * Define Error Flags > + */ > +#define RTEMS_ERROR_BITS (sizeof(rtems_error_code_t) * CHAR_BIT) > + > +#define RTEMS_ERROR_ERRNO (((rtems_error_code_t)1) << (RTEMS_ERROR_BITS - > 2)) > + > +#define RTEMS_ERROR_PANIC (((rtems_error_code_t)1) << (RTEMS_ERROR_BITS - > 3)) > + > +#define RTEMS_ERROR_ABORT (((rtems_error_code_t)1) << (RTEMS_ERROR_BITS - > 4)) I understand the previous version was easier to read.But it failed as it performs the shift on a literal 1 of type int, which makes it dependent on the host int size. This can lead to undefined behavior on 16-bit hosts which we may ignore once. Also computing the bit position using my logic removes our reliance on the hard coded constants and makes our version portable on 32 and 64 bit configs. I wished to ensure typesafety and portability here. If you wish I can add a short explanatory comment to make my intent clearer, but I'll still prefer the direct form -- View it on GitLab: https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/1069#note_143192 You're receiving this email because of your account on gitlab.rtems.org.
_______________________________________________ bugs mailing list [email protected] http://lists.rtems.org/mailman/listinfo/bugs
