Go Down

Topic: When to use a .C library vs a .CPP library (Read 834 times) previous topic - next topic


I am copying the wiring_serial library for testing.  I want to create a new "test_serial" with my mods.  Hopefully that avoids the risks of continuing to edit the core code.  

My question is, HardwareSerial.cpp appears to simply call "wiring.serial.c"  presumably to put a C++ face on it.   Is there any reason I cannot make my new library a .CPP to start with?  It looks like you can hook interrupts in .CPP.   Or for that matter is there any problem with creating a .C library and distributing it?


Jan 24, 2009, 05:22 am Last Edit: Jan 24, 2009, 05:25 am by halley Reason: 1

Feel free to make libraries written in C++.  I think the existing libraries don't go all out and make it all C++ so that the syntax is slightly less confusing for newcomers or C programmers, but C++ can really serve the needs of small programs just as well as C.

If you're going to make C library functions usable from a user's C++ sketch, you just need to ensure that your header file is explicit about its C nature.

Code: [Select]

[glow]#ifdef __cplusplus
extern C {

/* prototypes for functions implemented in C */
int myCfunction(float, char, int);

[glow]#ifdef __cplusplus
} // extern C


Thanks - thats just what I needed.  I didnt understand th C header.

Go Up