Timeline for Arduino sizeof Servo array objects is.. wrong?
Current License: CC BY-SA 3.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 7, 2014 at 21:04 | vote | accept | briosheje | ||
| May 7, 2014 at 19:30 | comment | added | JRobert |
My point was that it's easier for someone to try a simple or trivial program showing the error that to try your - likely hardware dependent - full program. To answer your question, I use this macro #define countof(a) (sizeof(a)/sizeof(a[0])) to find the # of elements in an array, but since it depends on sizeof() it's won't be much help to you.
|
|
| May 7, 2014 at 18:58 | answer | added | jfpoilpret | timeline score: 7 | |
| May 7, 2014 at 13:12 | comment | added | briosheje |
@JRobert: Tonight I'll post the whole code, even though, as I said above, the array is declared (and filled) right before the setup and even if I print the sizeof at the start of my loop, it still outputs the same value as in the function where I'm using it. Also, is there any alternative to check if an array element exists? If it's possible, then I could make my own sizeof prototype.
|
|
| May 7, 2014 at 12:40 | comment | added | JRobert | It would help if you post a version of your code cut down to the minimum necessary to demonstrate the erroneous returns. | |
| May 7, 2014 at 7:11 | comment | added | briosheje |
@jfpoilpret: arduino supports the standard sizeof construct available for any array object. Therefore, any array (ex. int elements[] = {2,3,1,3,9};) outputs its correct value (in the previous case 5) and I'm getting the value directly from the Serial port. In any case, tonight, I will upload the whole code, I'm not and home and can't really paste it from my Nexus 5 :P
|
|
| May 7, 2014 at 4:59 | comment | added | jfpoilpret | What you describe is weird; could you please post the exact code that calculate the size of the array and displays it (I suppose this is through Serial)? | |
| May 6, 2014 at 23:54 | history | migrated | from electronics.stackexchange.com (revisions) | ||
| May 6, 2014 at 23:29 | history | asked | briosheje | CC BY-SA 3.0 |