Skip to content
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

SD library: Declare path parameter on all functions as const #3998

Merged
merged 1 commit into from
Oct 22, 2015
Merged

SD library: Declare path parameter on all functions as const #3998

merged 1 commit into from
Oct 22, 2015

Conversation

Ivan-Perez
Copy link
Contributor

This way we will avoid some warnings when using paths as constants in #define's.

For example:

#define MY_FILE "file.txt"
SD.exists(MY_FILE);

Raises this warning using the -Wwrite-string option of compiler:
warning: deprecated conversion from string constant to 'char*'

After adding those const, this warning desappears.

Existing code is not affected by these minor changes in any case.

This way we will avoid some warnings when using paths as constants in
#define's

`warning: deprecated conversion from string constant to 'char*'`
@cmaglie
Copy link
Member

cmaglie commented Oct 20, 2015

@ArduinoBot build this please

@cmaglie cmaglie self-assigned this Oct 20, 2015
@cmaglie cmaglie added feature request A request to make an enhancement (not a bug fix) Library: SD The SD Arduino library labels Oct 20, 2015
@Ivan-Perez
Copy link
Contributor Author

Another signature method in the library that should be changed as well is char* File::name() (https://github.com/arduino/Arduino/blob/master/libraries/SD/src/SD.h#L48), as anyone could change the internal name used in the object, which is not correct.

I didn't do the change because it may break existing code, although it should be fixed easily. For example:

File file = File("test.txt");
char* name = file.name();// now it compiles, but it won't after we add that const
const char* name = file.name();// valid after proposed change on this comment done (and before the change, too)

May I update the pull request and add that change?

@facchinm
Copy link
Member

@Ivan-Perez , of course you can update the PR by pushing another commit on the top of your topic branch 😄
Anyway, being a breaking change, I'd strongly suggest you to open another PR once this one gets merged

@cmaglie cmaglie added this to the Release 1.6.6 milestone Oct 22, 2015
@cmaglie cmaglie merged commit e3fae38 into arduino:master Oct 22, 2015
@cmaglie
Copy link
Member

cmaglie commented Oct 22, 2015

Thank you!

About the breaking change in file.name(); I'd avoid it (unless there is a stronger reason to do it anyway that I'm missing).

@Ivan-Perez
Copy link
Contributor Author

Maybe on the next major release the change can be included. It's not an important change though, but for correctness that variable should be returned as const.

If you think the change is ok I can prepare another PR now so you can merge it whenever you want.

Thanks!!

@tigoe
Copy link
Member

tigoe commented Nov 12, 2015

Probably related to this, the 1.6.6 IDE insists that the SD and Servo libraries are out of date, and even if you let the library manager update them, the error persists.

@per1234
Copy link
Collaborator

per1234 commented Nov 12, 2015

@tigoe I had the same issue. I found it was caused by the copies of these libraries in the Mighty 1284P 3rd party hardware core I have installed. It only happens when I have one of the Mighty 1284P boards selected. The solution I found is here: JChristensen/mighty-1284p#23. So even if you don't have Mighty 1284P installed you might be having a similar problem.

@tigoe
Copy link
Member

tigoe commented Nov 12, 2015

I don't but you're right that it may be related to particular libraries, as I was able to get the redBear labs libraries to install just fine. Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A request to make an enhancement (not a bug fix) Library: SD The SD Arduino library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants