Advertisement
chayanforyou

Using C files in Arduino

Jul 7th, 2023
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. The .ino files of Arduino sketches are compiled as C++ after a little bit of preprocessing. If you want to use C functions in C++, you need to wrap their declarations in:
  2.  
  3. extern "C" {}
  4. There are a couple ways you can do this:
  5.  
  6. In the sketch:
  7.  
  8. extern "C" {
  9. #include "SomeCFunctions.h"
  10. }
  11. Or, in the .h file:
  12.  
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16.  
  17. // C function declarations here
  18.  
  19. #ifdef __cplusplus
  20. }
  21. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement