![]() ![]() ![]() ![]() Next: Character Strings Up: Key/Value Tables Previous: A Simple Example Contents Arrays as Table ValuesAs well as a single numbers (or characters or pointers), tables can also store 1-dimensional arrays of numbers (or characters or pointers).part175 For example (continuing the previous example): static const CCTK_INT a[3] = { 42, 69, 105 }; if (Util_TableSetIntArray(handle, 3, a, "my array") < 0) CCTK_WARN(CCTK_WARN_ABORT, "couldn't set integer array value in table!"); ... CCTK_INT blah[10]; int count = Util_TableGetIntArray(handle, 10, blah, "my array"); if (count < 0) CCTK_WARN(CCTK_WARN_ABORT, "couldn't get integer array value from table!"); /* now count = 3, blah[0] = 42, blah[1] = 69, blah[2] = 105, */ /* and all remaining elements of blah[] are unchanged */As you can see, a table entry remembers the length of any array value that has been stored in it.part176 If you only want the first few values of a larger array, just pass in the appropriate length of your array, that's OK: CCTK_INT blah2[2]; int count = Util_TableGetIntArray(handle, 2, blah2, "my array"); if (count < 0) CCTK_WARN(CCTK_WARN_ABORT, "couldn't get integer array value from table!"); /* now count = 3, blah2[0] = 42, blah2[1] = 69 */You can even ask for just the first value: CCTK_INT blah1; int count = Util_TableGetInt(handle, &blah1, "my array"); if (count < 0) CCTK_WARN(CCTK_WARN_ABORT, "couldn't get integer array value from table!"); /* now count = 3, blah1 = 42 */
|