Odd compiler warning?

jim lee

Well-known member
I get this :
Code:
/Users/dads/Documents/GIthub/Arduino/libraries/LC_blockFile/src/blockFile.cpp: In member function 'bool blockFile::fOpen()':
/Users/dads/Documents/GIthub/Arduino/libraries/LC_blockFile/src/blockFile.cpp:295:48: warning: unsigned conversion from 'int' to 'uint8_t' {aka 'unsigned char'} changes value from '513' to '1' [-Woverflow]
  295 |   mFile = SD.open(mFilePath, (O_READ | O_WRITE | O_CREAT));

I'm wondering what it's upset about? I don't know what I'm doing wrong here. It seems really straight forward to me.

Thanks!
 
SD::open() doesn’t take a set of bitwise flags for its second parameter, it takes one of three “mode” values: FILE_READ, FILE_WRITE or FILE_WRITE_BEGIN. This is of type uint8_t, hence the erroneous value 513 that you got from or’ing together flags is too big for it, and the compiler complains.

Lucky, really - if it had fitted then you’d get no error, but your code would fail to work…
 
Back
Top