-
Notifications
You must be signed in to change notification settings - Fork 524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.2.3 fails to compile #490
Comments
You may be using the copy constructor for FsFile. It is explicitly deleted here. It is deleted since filesystem corruption can occur if there are multiple instance of the file object for a file. |
These are the compile time error messages: C:\Users\Thomas\Documents\Arduino\Projects\CH4_Flux\CH4_Flux.ino: In function 'void DirectoryList()': exit status 1 Compilation error: use of deleted function 'FsFile::FsFile(const FsFile&)' |
This is my initialisation code as per your examples: // --------------- SDFat includes ------------------------------------------- #include "SdFat.h" // SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h, // SDCARD_SS_PIN is defined for the built-in SD on some boards. // Try max SPI clock for an SD. Reduce SPI_CLOCK if errors occur. // Try to select the best SD card configuration. #if SD_FAT_TYPE == 0 |
The board is a Adafruit ESP32 Feather. The code as working well with your version 2.2.2 |
I did not alter SdFatConfig.h, in any way |
I had the same issue when I upgraded SdFat for my project. Since @greiman explained the rationale behind the deletion of copy constructor (to avoid potential corruption files), I can only accept the decision as it sounds pertinent. I simply replace this way: I could also use |
Functions like this with call by value cause problems. The reason is that a copy of the first argument is made on the stack before a call. Any changes to the file are lost. In the case of PrintDirectory the only changes such as file position may not mater. In cases where a file is open for write, the FAT table may be corrupted. You can change the function to call by reference like this: Then only one instance of the file object will exist. Try this example. Remove comment from call to listDirValue(root) to see the error.
Here is test output from the above program:
Another way is to defeat the protection by editing SdFatConfig.h here to make the copy constructor public. |
I made the change since even a very skilled C++ programmer created a bug using call by value and suggested I protect from duplicate instances of the file object. I agreed and it saves me from debugging programs that have filesystem corruption. |
Excellent thank you, my mistake. Sent from my Galaxy
-------- Original message --------From: Bill Greiman ***@***.***> Date: 12/08/24 3:08 am (GMT+12:00) To: greiman/SdFat ***@***.***> Cc: teverth ***@***.***>, Author ***@***.***> Subject: Re: [greiman/SdFat] 2.2.3 fails to compile (Issue #490)
Functions like this with call by value cause problems.
void printDirectory(File dir, int numTabs)
The reason is that a copy of the first argument is made on the stack before a call. Any changes to the file are lost.
In the case of PrintDirectory the only changes such as file position may not mater. In cases where a file is open for write, the FAT table may be corrupted.
You can change the function to call by reference like this:
void printDirectory(File &dir, int numTabs)
Then only one instance of the file object will exist.
Try this example. Remove comment from call to listDirValue(root) to see the error.
#include "SdFat.h"
SdFs sd;
FsFile root;
void listDirValue(FsFile dir) {
dir.ls();
}
void listDirReference(FsFile &dir) {
dir.ls();
}
void setup() {
Serial.begin(9600);
sd.begin();
root.open("/");
listDirReference(root);
// Call by value won't compile
// listDirValue(root);
}
void loop() {}
Here is test output from the above program:
bench.dat
bench0.txt
bench1.txt
bench2.txt
bench3.txt
bench4.txt
bench5.txt
Another way is to defeat the protection by editing SdFatConfig.h here to make the copy creator public.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Version 2.2.3 fails to compile on ESP32 board (or perhaps others too).
'FsFile::FsFile(const FsFile&)' is implicitly deleted because the default definition would be ill-formed
The text was updated successfully, but these errors were encountered: