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

make operator new inline to avoid duplicates during linking #13

Merged
merged 1 commit into from
Jun 7, 2021

Conversation

mo22
Copy link
Contributor

@mo22 mo22 commented Jun 7, 2021

No description provided.

@domschl
Copy link
Member

domschl commented Jun 7, 2021

Which platform define did you use?

Some arduino SDKs do define a new operator and others don't. This is currently handled by the feature-define USTD_FEATURE_SUPPORTS_NEW_OPERATOR, so that platforms that have a new operator implementation simply define this.
Making this inline effectively causes two different new implementations without the compiler noticing, so that could be problematic.

@mo22
Copy link
Contributor Author

mo22 commented Jun 7, 2021

Hi, I'm using platformio + Arduino nano, which does not have that operator defined.

The issue is that if you have two cpp files (a.cpp and b.cpp) that both include functional.h you'll end up with two instances of that operator implementation causing a linker error.

Defining that function inline prevents that. An alternative would be to just have the prototype in the header file and move the implementation to a c file.

@domschl
Copy link
Member

domschl commented Jun 7, 2021

Hmm. That's a valid point.
A hacky solution would be to #define USTD_FEATURE_SUPPORTS_NEW_OPERATOR in one of the cpp files before including ustd_functional.h.
Need to think about this more.

@mo22
Copy link
Contributor Author

mo22 commented Jun 7, 2021

Unfortunately that hack does not work, as there is no definition of that function in Arduino.h or something. So then that implementation would exist but there is no header definition for that :/

@domschl
Copy link
Member

domschl commented Jun 7, 2021

I guess you're right, it's going to be inline.
This problem also affects other global functions e.g. in ustd_platform.h.
I've to investigate the extend a bit more...

@domschl domschl changed the base branch from master to inline June 7, 2021 14:21
@domschl domschl merged commit 86395bf into muwerk:inline Jun 7, 2021
@domschl
Copy link
Member

domschl commented Jun 7, 2021

Release 0.6.2 is published in platformio, thank you!

@mo22
Copy link
Contributor Author

mo22 commented Jun 7, 2021

Thank you very much, greatly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants