Giter VIP home page Giter VIP logo

Comments (5)

MockbaTheBorg avatar MockbaTheBorg commented on August 21, 2024

Hi Garry,

Thanks for using RunCPM.

This is strange.
I have just compiled RunCPM for my Arduino Due and didn't get any warnings. I am using Arduino 1.8.9 too, which I have just installed. SdFat by Bill Greiman version 1.1.0.
Did you make any change to any configuration that you would remember? Maybe to compile a different project? Maybe you're not using the regular Greiman's SdFat library?
This is the definition of f.write() inside the library:

  /** Write a single byte.
   * \param[in] b The byte to be written.
   * \return +1 for success or -1 for failure.
   */
  int write(uint8_t b) {
    return write(&b, 1);
  }

So it is supposed to be less than 0 if there's an error.
The return value of this function is not unsigned, so nothing to fix there.
Please check it out and let me know. I am happy to assist more if needed.

Cheers,
Marcelo.

from runcpm.

plainpylut avatar plainpylut commented on August 21, 2024

Marcelo,
Correct, however, when I compile original (unmodified) RunCPM, using SDFat library with 1 file modified, I get a warning that is critical. It shows the code will never be executed.

Here is what I did:
Copy extracted RunCPM distro into my Sketch subdir with name RunCPM
Start Arduino IDE
Manage Libraries -> Install "SDFat library version 1.1.0".
Edit SdFatConfig.h in actual disk install location, per this info in RunCpm.ino:
// SdFatSoftSpiEX and SdFatEX require changes to the following lines on SdFatConfig.h:
// #define ENABLE_EXTENDED_TRANSFER_CLASS (from 0 to 1 - around line 71)
// #define ENABLE_SOFTWARE_SPI_CLASS (from 0 to 1 - around line 87)
Restart Arduino IDE
Preferences -> "Show verbose output during compiling" -> Compiler warnings -> "ALL"
Load RunCPM sketch
Compile Sketch
The following "Warning" is displayed:
In file included from C:\Users\kraemerg\Documents\Arduino\Sketches\RunCPM\RunCPM\RunCPM.ino:49:0:

C:\Users\kraemerg\AppData\Local\Temp\arduino_build_251570\sketch\abstraction_arduino.h: In function 'bool _sys_extendfile(char*, long unsigned int)':

C:\Users\kraemerg\AppData\Local\Temp\arduino_build_251570\sketch\abstraction_arduino.h:171:31: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]

 if ((f.write((uint8_t)0)) < 0) {

                           ^

The Warning states the "If statement will never be executed (entered)!

Casting the f.write() return value stops the warning.
if ((int)(f.write((uint8_t)0)) < 0) {
result = false;
break;
}
I'm not sure if this is the correct way to fix the issue.

Thanks

Garry

from runcpm.

plainpylut avatar plainpylut commented on August 21, 2024

Marcelo,
This looks to be the way to fix the routine:
bool _sys_extendfile(char *fn, unsigned long fpos)
{
uint8 result = true;
File f;
unsigned long i;
int zero = 0;
digitalWrite(LED, HIGH^LEDinv);
if (f = SD.open(fn, O_WRITE | O_APPEND)) {
if (fpos > f.size()) {
for (i = 0; i < f.size() - fpos; ++i) {
if ((f.write((uint8_t)0)) < zero) {
result = false;
break;
}
}
}
f.close();
} else {
result = false;
}
digitalWrite(LED, LOW^LEDinv);
return(result);
}
Declaring a local integer value 'zero' and initializing it makes sure it is an integer.
Now the logical test using the f.write return value properly compares the integer variable 'zero'
I still don't understand exactly why '0' is unsigned, unless it is treated as a character.
I have never run into this in 20 years of software engineering.
Garry

from runcpm.

MockbaTheBorg avatar MockbaTheBorg commented on August 21, 2024

Yes, this is very strange ... if the compiler is not dumb (which seems to be the case) it should just interpret the numeric value as having the same type as to the expression to the left, being it a constant.

But anyways, one more compiler quirk that we have to work around. I will make the change to the official code branch, as I hate warnings too. :)

from runcpm.

MockbaTheBorg avatar MockbaTheBorg commented on August 21, 2024

I have changed the code to:

if (f.write((uint8_t)0) != 1)

This should work as the library states it returns 1 for success.
So no more warning, please run some tests if possible.

from runcpm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.