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

Avoid error: call of overloaded 'abs(long unsigned int)' is ambiguous… #41

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

aurelihein
Copy link

We got compilation error when compiling for stm32
Because manipulation of long unsigned int into abs math function is ambiguous and fail with call of overloaded 'abs(long unsigned int)' is ambiguous
Creating a simple function that handle the absolute result of the difference of two unsigned long will always work
Regards,

@Masood-Salik
Copy link

This error message is caused by an ambiguous call to the abs() function in the CapacitiveSensor library's capacitiveSensor() function. The compiler is unsure which abs() function to use since there are multiple overloaded versions of abs() available in different header files.

To fix this error, you can explicitly cast the arguments to the abs() function to the desired type. In this case, you can cast total and leastTotal to long int since that is the type expected by the abs() function in the math.h library, which is the one you likely intended to use.

Replace the line:
if ( (millis() - lastCal > CS_AutocaL_Millis) && abs(total - leastTotal) < (int)(.10 * (float)leastTotal) ) {

with this line
if ( (millis() - lastCal > CS_AutocaL_Millis) && abs((long int)total - (long int)leastTotal) < (int)(.10 * (float)leastTotal) ) {

This should resolve the ambiguity and allow the code to compile successfully.

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.

2 participants