I believe this is an entry level question about the basic functionality of uploading a sketch to an Arduino. Keeping in mind that the sketch ends up on the 32 KB Flash (plus however you can use the EEPROM), I plan on writing a sketch that uses various libraries (Crypto, RF, RFID) but then saw that the libraries are bigger than 32KB combined. I've searched for other libraries that may or may not have to do with my project and saw that most of them are in fact bigger than 32KB. What am I missing here? Is the sketch only exported to the Arduino with the required functions of the libraries it uses? Or are the sketch+libraries exported in total to the Arduino? Thank you for shedding some light on the subject.
Asked
Active
Viewed 579 times
2
-
Arduino is neither C nor C++. – too honest for this site Oct 29 '15 at 18:12
-
1Oh, come on @Olaf, arduino IS C++ with some additional libraries.... Otherwise you couldn't use a C++ compiler to, well, compile. As for the original question, how did you measure the library size? Usually all you use is compiled, and most of what you don't use is not compiled. And if in the end the library is bigger than 32kB, well, what would you do if you need 10GB on your HDD and you only have a 8GB HDD? You buy a bigger one! So if you need more than 32kB and can0't remove anything perhaps you need a bigger board... – frarugi87 Oct 29 '15 at 22:01
-
@frarugi87: No, Arduino code is first preprocessed/header added. Itr is no valid C++ program as-is. And definitively not C! – too honest for this site Oct 30 '15 at 01:27
-
How are you determining the sizes of the libraries? – Ignacio Vazquez-Abrams Oct 30 '15 at 04:55
-
@Olaf AFAIK the only "preprocessing" Arduino IDE does is to concatenate all the files into one. And if adding headers makes a program not-C++, well, what is C++ then? – frarugi87 Oct 30 '15 at 09:35
-
Hello and thanks for your responses. I only download the libraries in zip format and see their sizes in KB, then add the zip library to the IDE and #include them in my code. @Olaf Arduino's sketches (programs) are written in C/C++ (Arduino's site / Le grand livre d'Arduino - Erik Bartmann) as well as the libraries, however their is no C/C++ on the Arduino; it's only machine language. Seems the more I read the more I understand about my own question, it seems that the sketch exported only includes the code and the used functions. Again, I'm new the whole coding scene so thanks for your patience – Rachad Maalouf Oct 30 '15 at 10:13
-
@RachadMaalouf: 1) There is no language C/C++. Scetches are definitively **not** C, as they use (among others) OOP syntax. C is not C++ and C++ is not "C with classes". There are enough answers here and elsewhere answering this; if they are not sufficient for you, I recommend reading both standards. 2) Arduino is a software+hardware platform with a tailored library&build system which hides some parts of the standard, thus you do not write standard-compiant programs (at least it hides `main()`. 3) For a similar reason it is useless to talk about machine language. ... – too honest for this site Oct 30 '15 at 12:49
-
... If you only use the hardware, you should talk about ATmega, not Arduino anymore, because the hardware alone is definitively not special and there are already quite some derivates. Finally: Yes, reading is a good thing to understand. You alsways should read first and do some research on your own. One advantage is you will read a lot of information you might not need instantly to answer your current problem, but might (sometimes will eventually) need later. This is the way to get a broad understanding/knowledge. A question/answer site cannot provide this. – too honest for this site Oct 30 '15 at 12:50
-
1@Olaf I still don't agree. Or, at least, I don't agree with tags removal. And the reason is: what is then C++? If you put just the "standard" C++ you won't go much far away from the "hello world" program. Every embedded platform has custom libraries, every OS has different ways to interact. A lot of people writing C++ code uses Microsoft Visual C++. So this is NOT C++, in your classification, since there are functions coming away from the C++ standard. So, should we remove all these questions from SO? Or you are just saying that "C++ must have a main"? – frarugi87 Nov 02 '15 at 09:08
-
@frarugi87: Finally: 1) I presume removal of the C tag is not under discussion. Leaving C++: **For example** you do not have to generate prototypes for functions, which is clearly required by the standards. Just read the C++ standard and compare it to Arduino programs. The output of the preprocessor might very well be valid C++ code, but that's not what one writes and we are discussing here. You have the last word. – too honest for this site Nov 02 '15 at 13:05
-
@Olaf of course Arduino is not C. But.. I think that this is exactly the same "problem" as tagging something as "C/C++". A program can either be C or C++, not both. But since the two languages are really similar, a lot of questions can be answered by experts from both "worlds": usually a solution to a C question is the same solution to the same question in C++. I think that arduino enough "close" to C++ that a lot of questions can be solved by C++ programmers. Even because here on SO usually people post part of the codes, not the whole program (so C++ questions rarely have includes or mains) – frarugi87 Nov 02 '15 at 15:39
-
@frarugi87: 1) There are different semantics in some aspects, e.g. `void *`, `const`, `enum`s, C provides features C++ doesn't (e.g. designated initialisers, VLAs), etc. 2) At least for non-trivial code, if you write the code in C++ as you do in C, you either should stick with C or you are doing something wrong. You should always use the features a language provides. C++ is not "C with classes". And no, C++ programmers are often stuck with Arduino, because they are not aware about the differences and don't know the libraries or quite special coding style. Not providing a [MCVE] is close-reason – too honest for this site Nov 02 '15 at 17:23