jamesbowman / i2cdriver

I2CDriver open source tools
https://i2cdriver.com/
BSD 3-Clause "New" or "Revised" License
187 stars 57 forks source link

I2CDRIVER.C won't compile with MSVC #16

Closed CrustyAuklet closed 5 years ago

CrustyAuklet commented 5 years ago

The following code fails to compile in Visual Studio 2019 with the error:

Severity    Code    Description File    Line    Suppression State
Error   C2133   'mm': unknown size  ..\i2cdriver.c  42  
Error   C2057   expected constant expression    ..\i2cdriver.c  42  
Error   C2466   cannot allocate an array of constant size 0 ..\i2cdriver.c  42  

https://github.com/jamesbowman/i2cdriver/blob/2697bf5046094cddbebcbdee89a480c77b5c3f22/c/common/i2cdriver.c#L40-L44

my quick fix:

    char mm[256];
    sprintf(mm, "%s failed with error %lu:\n%s", func_name, dw, (char*)lpMsgBuf);

unsure if there is a better way, just wanted to open the issue.

Also, I would suggest placing #define NOMINMAX before including windows.h to prevent windows from defining the min and max macros and clashing with other code.

CrustyAuklet commented 5 years ago

Also noticed that I had moved #include <unistd.h> to the #if !defined(WIN32) section since MSVC doesn't have that header and mingw doesn't need it. Also a == where i think there should be a = on line 58.

If you want I can fork and open a pull request to group these things together, I am using both the I2C driver and SPI driver pretty heavily in MSVC at work.