arduino / ArduinoCore-mbed

345 stars 199 forks source link

Binary constants - enum implementation, leading to severe macro-coditioning compilation errors #894

Closed GiorgosXou closed 4 months ago

GiorgosXou commented 4 months ago

Intro

My library-NeuralNetworks is based on B01...-constants for providing easy-to-use optimizations. Recently, a user of my library, reported having issues compiling it for "Arduino Nano 33 BLE". After some investigation, I realised that those constants are "deprecated" (for an unkown-to-me and potentially faulty reason):

binary.h - Definitions for binary constants Deprecated -- use 0b binary literals instead

Issue

(To my knowledge) Compiling something like this, should work just fine for most cores:

// And indeed, it does work for most I've tested.
#define _1_OPTIMIZE B01000000

#if ((_1_OPTIMIZE bitor B10111111) == B11111111)
  #pragma message("Optimization B01000000 is enabled")
#endif 
#if ((_1_OPTIMIZE bitor B01111111) == B11111111)
  #pragma message("Optimization B10000000 shouldn't be enabled !!!!!")
#endif 

But, instead: due to this enum implementation for "ArduinoCore-mbed" , only when replacing those B0-constants with the 0b-constant-literals works [...] (With all my respect) I'm not sure if this is wise, considering how it's implemented on most cores I've seen so far...

Questions

  1. If Binary.h states that:

    /* If supported, 0b binary literals are preferable to these constants.

then, why would someone implement those constants in such a way that doesn't represent those literals? (considering that __cpp_binary_literals are macros [and therefore B0..-constants should be too])

  1. Why deprecate those constants at all?

Outro

Forgive me if I'm being naive or stupid, I might be completly wrong or missed something... but thank you for your work and the time you took to read this.

ArduinoCore-avr VS ArduinoCore-mbed
image image
GiorgosXou commented 4 months ago

Ah.. esp32 core by espresiff seem to do the same (since I don't know when... but used to work just fine) anyways... I'll figure it out via another way... I guess this is the theme now :P