Skip to content

Commit a62570c

Browse files
committed
Expanded 02_basic with more access examples
1 parent d419652 commit a62570c

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

examples/2_basic/main.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,35 @@ int main()
1515
{
1616
stored::ExampleBasic e;
1717

18-
// Initialized value.
18+
// Initialized value:
1919
printf("test42=%" PRId8 "\n", e.test42.get());
2020

2121
// The thing with the space around the =
2222
printf("_42_test42=%" PRId8 "\n", e._42_test42.get());
2323

24-
// The initialized array element.
25-
printf("three ints[1]=%" PRId16 "\n", e.three_ints_1.get());
24+
// The initialized array element:
25+
printf("three ints[0]=%" PRId16 "\n", e.three_ints_0.get());
26+
27+
// Next element through array-like access:
28+
printf("three ints[1]=%" PRId16 "\n", e.three_ints_a(1).get<int16_t>());
29+
30+
// An initialized string:
31+
char txt[8];
32+
e.string_hello.get(txt, 8);
33+
printf("string hello='%s'\n", txt);
34+
35+
// Change a value by direct assignment:
36+
e.f = 3.14F;
37+
38+
// Or using a setter:
39+
e.d.set(2.718);
40+
41+
// Same for array elements (which are really just variables):
42+
e.four_ints_0 = 66;
43+
44+
// Write to array with:
45+
const char new_txt[] = "apples";
46+
e.string_hello.set(new_txt, sizeof(new_txt));
2647

2748
return 0;
2849
}

0 commit comments

Comments
 (0)