emailing-files-is-still-better / Ir-Blinky

PIC IR blinker for simple raw data
2 stars 1 forks source link

Adding a function for transmitting an array #10

Closed georgev93 closed 1 year ago

georgev93 commented 1 year ago

Explainations to follow in individual comments in the code

georgev93 commented 1 year ago

Actually, I'll just leave the explaination here because it's more weaved throughout the PR.

Pointers

Pointers are great. Yet they are a very scary/infamous thing to many beginners. When using variables, you can use these symbols:

You can see I've also created a variable of type bool*. That means that variable contains an address to a bool type variable

Arrays and Pointers

Technically, an array is just an implementation of a pointer. If I create an array called foo, and that has three elements that I load with "A", "B", and "C". The following is true:

So really, an array is just a pointer that can be "dereferenced" with a fancy notation of appending a [x] after the variable name.

So in the code, I refer to the start of an array as a pointer. I do so by saying &array[0] which translates to "the address of the first element of this array". Could I have just said "array" instead? Since that's a pointer to the array? Absolutely. But it's more likely that people just referring to an array without choosing an element might be making a mistake, whereas the &array[0] is much more deliberate. It also, in my opinion, is clearer at conveying the intention.

Anywho, what's with the &array[0] usage? I think it's clearest. Also, some code linters out there will throw a warning enforcing this best practice. Sometimes even the compiler will throw that same warning, so it's been beaten into me to do it this way

emailing-files-is-still-better commented 1 year ago

Merged from my phone because the code all looks excellent. I'll be honest, the pointers and arrays are still not quite clear to me. These will require some coffee chats where I ask lots of dumb questions like Michael needing it explained to him like he's 5.