Timeline for Different questions regarding Arduino C++ library coding style
Current License: CC BY-SA 3.0
17 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 2, 2017 at 16:33 | comment | added | R1S8K | Oh yeah, so clear thank you very much, I'm really happy with your answers :) Please see my new post at avrfreaks, but didn't find a quite clear answer. avrfreaks.net/forum/twen-twint, or I should post it in this website in a new topic? Regards, | |
| Apr 29, 2017 at 10:48 | comment | added | Majenko |
@PerchEagle The bulk of the Wire library code is actually a third party (probably written by Atmel) C library of routines. The TwoWire class is merely a C++ wrapper to those C functions to give an easy user interface. TwoWire::setClock merely calls the relevant function in that library (which is all in the utility directory) to do the actual setting of the clock.
|
|
| Apr 29, 2017 at 7:33 | comment | added | R1S8K | I got another question today :) Why the author put two functions to se the frequency or the clock? Regards, void TwoWire::setClock(uint32_t clock) { twi_setFrequency(clock); } | |
| Apr 28, 2017 at 18:08 | comment | added | R1S8K | Absolutely thank you for your answers I'm really thankful for your cooperation I've been away of coding because I was busy with my marriage and honeymoon it's been 1 month for my marriage :) I just started off reviewing coding these days :) | |
| Apr 28, 2017 at 18:06 | comment | added | R1S8K | Thank you very much for helping me Re 2, 3, 4 are OK to me because I have to implement these techniques to see the results for C++ applications. | |
| Apr 28, 2017 at 18:03 | comment | added | Majenko | Because static storage happens to be the correct solution to a specific problem. | |
| Apr 28, 2017 at 18:03 | comment | added | R1S8K | OK, I understood your reply and the Servo example, but why would I need static variables anyway if its storage is shared with all instances? | |
| Apr 28, 2017 at 18:01 | comment | added | Majenko | Re 2: It is not a question of "benefit" - it's a question of how do you implement storing a function passed to you as a parameter, and function pointers are the answer. Re 3: Because he wanted to. It's a clean way of doing it, and you only have to remember "begin", not "beginMaster" and "beginSlaveInt" and "beginSlaveUint8" functions. Re 4: Which would you prefer: to write the same code 3 times or write it once and just call the function with it in? | |
| Apr 28, 2017 at 17:58 | comment | added | R1S8K | 2. The second answer is not obvious because I didn't implement it practically in my AVR C coding yet so I don't know the benefits of function pointers. 3. The third answer is obvious which is function overloading and now I see an example for function overloading but I don't know why the author implemented this function overloading. 4. The fourth answer is not clear. | |
| Apr 28, 2017 at 17:53 | comment | added | Majenko |
... <ClassName>::<VariableName>. You need the <ClassName>:: bit so that the compiler knows you mean the variable in that class, not some other unrelated variable.
|
|
| Apr 28, 2017 at 17:53 | comment | added | Majenko |
@PerchEagle With a static variable the type is defined in the class, but the storage space for that variable has to be manually defined, and that is what those entries are. A normal variable has the storage space allocated in a class instance when it is created (e.g., Servo myServo; allocates the space for the variables within the Servo class). Static variables can't do that since the storage space isn't specific to any one object, but to all objects - so you have to manually create that storage space. And you do that by defining the variables in a source file. The variable's name is ...
|
|
| Apr 28, 2017 at 17:50 | comment | added | R1S8K | 1. For the fisrt answer, I understood half of your answer as static variables are shared and that's it but I didn't understand the second half, "so they have to be defined elsewhere, and for that you need the full "class path" for them to associate them with the class itself." Do you mean by full path is to define their type and connect them with the class name? I think yes, and also I understood in the library that the author is defining them at the beginning and before class definition with the class name. OK this point is now obvious to me :) | |
| Apr 28, 2017 at 14:55 | comment | added | Majenko | There are some complex things there you are looking at. May help: learncpp.com/cpp-tutorial/811-static-member-variables - tutorialspoint.com/cplusplus/cpp_overloading.htm | |
| Apr 28, 2017 at 14:54 | comment | added | R1S8K | Guys, first of all thank you very much for Mr Code Gorilla for correcting my English it's really a honor for me that a friend in the technical field is interested to help me with my English skills :), and secondly, thanks to Mr Majenko for answering my questions. I'm really thrilled that one help me with my English and the other one helped me with my technical topic. I understood some answers and others not so quite, so I need more time to understand and comment again for the answers. | |
| Apr 28, 2017 at 14:33 | vote | accept | R1S8K | ||
| Apr 28, 2017 at 11:53 | history | edited | Code Gorilla | CC BY-SA 3.0 |
Editing the question meant the quated parts of the answer needed updating.
|
| Apr 28, 2017 at 11:29 | history | answered | Majenko | CC BY-SA 3.0 |