Skip to content

Compiler does not detect when the type of function pointers are different #2199

@gilman88

Description

@gilman88

Describe the problem

This came to my attention from a contributor in this PR who was trying to fix compile errors for a RP2040 platform. I found that the compiler was ignoring differences in the return types (bool vs void) when assigning the function pointer to a variable, I did some more poking and found that it would also ignore differences in argument types both within the library code and in end user code. I also tried finding another library that I could replicate the issue using one of their examples and was able to change the return type, the function didn't have arguments to try changing but it did give an error if I added an argument

To reproduce

Example 1

  • Setup the example code here
  • Change the return type of the saveParamCallback method (bool/long long/etc)
  • Compile the project

Example 2

  • Setup the example code here
  • Define an empty function void foo(void *blk_id, size_t idSize, byte *data, size_t dataSize) {}
  • Add xmodem.setBlockLookupHandler(foo) to the setup function
  • Change the return types and argument types of the foo function
  • Compile the project

Expected behavior

The compiler should return an error about incompatible function pointer types

Arduino CLI version

arduino-cli Version: nightly-20230605 Commit: f3ee0a8 Date: 2023-06-05T01:36:01Z

Operating system

Linux

Operating system version

Arch Linux

Additional context

No response

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions