NETMF / netmf-interpreter

.NET Micro Framework Interpreter
http://netmf.github.io/netmf-interpreter/
Other
487 stars 223 forks source link

Mismatch between struct MediaAttribute and BlockDeviceInfo init in Solutions? #471

Open doingnz opened 8 years ago

doingnz commented 8 years ago

BlockStorage_decl.h defines

struct MediaAttribute
{
    BOOL Removable :1;
    BOOL SupportsXIP:1;
    BOOL WriteProtected:1;
    BOOL SupportsCopyBack:1;
    BOOL ErasedBitsAreZero:1;
};

The Solutions do not explicitly set ErasedBitsAreZero.

eg: for STM32F4DISCOVERY

const BlockDeviceInfo g_STM32F4_DeviceInfo=
{
    {  
        STM32F4__IS_REMOVABLE,             // BOOL Removable;
        STM32F4__SUPPORTS_XIP,             // BOOL SupportsXIP;
        STM32F4__WRITE_PROTECTED,          // BOOL WriteProtected;
        STM32F4__SUPP_COPY_BACK            // BOOL SupportsCopyBack
    }
...

Need

#define STM32F4__ERASED_BITS_ARE_ZERO  FALSE

And

const BlockDeviceInfo g_STM32F4_DeviceInfo=
{
    {  
        STM32F4__IS_REMOVABLE,             // BOOL Removable;
        STM32F4__SUPPORTS_XIP,             // BOOL SupportsXIP;
        STM32F4__WRITE_PROTECTED,          // BOOL WriteProtected;
        STM32F4__SUPP_COPY_BACK,           // BOOL SupportsCopyBack
        STM32F4__ERASED_BITS_ARE_ZERO      // BOOL ErasedBitsAreZero
    },
...
cw2 commented 8 years ago

Hm, I would be very surprised if the 'missing' bit field was not automatically set to zero, due to the rules that apply for partial initialization (starting point for C/C++ standard references at http://stackoverflow.com/a/10828333, specifically for bit fields http://stackoverflow.com/a/34857037).

doingnz commented 8 years ago

Yes, thankfully the default value of zero is OK.

Explicit initialization would show a conscious decision was made. And its a heads up to anyone cloning the solution.

smaillet-ms commented 8 years ago

That's trivial enough - feel free to submit a PR that includes setting that.