1.21 By the way.
.byte 0, 0
aFebruary: .ascii "February"<0>
.byte 0
aMarch: .ascii "March"<0>
.byte 0, 0, 0, 0
aApril: .ascii "April"<0>
.byte 0, 0, 0, 0
aMay: .ascii "May"<0>
.byte 0, 0, 0, 0, 0, 0
aJune: .ascii "June"<0>
.byte 0, 0, 0, 0, 0
aJuly: .ascii "July"<0>
.byte 0, 0, 0, 0, 0
aAugust: .ascii "August"<0>
.byte 0, 0, 0
aSeptember: .ascii "September"<0>
aOctober: .ascii "October"<0>
.byte 0, 0
aNovember: .ascii "November"<0>
.byte 0
aDecember: .ascii "December"<0>
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0
Conclusion
Thisisabitold-schooltechniquetostoretextstrings. YoumayfindalotofitinOracleRDBMS,forexample.
It’s hard to say if it’s worth doing on modern computers. Nevertheless, it is a good example of arrays, so
it was added to this book.
1.20.8 Conclusion.
An array is a pack of values in memory located adjacently.
It’s true for any element type, including structures.
Access to a specific array element is just a calculation of its address.
1.21 By the way
So, pointer to an array and address of a first element—is the same thing. This is whyptr[0]and*ptr
expressions are equivalent in C/C++. It’s interesting to note that Hex-Rays often replaces the first by the
second. It does so when it have no idea that it works with pointer to the whole array, and thinks that this
is a pointer to single variable.
1.21.1 Exercises.
- http://challenges.re/62
- http://challenges.re/63
- http://challenges.re/64
- http://challenges.re/65
- http://challenges.re/66
1.22 Manipulating specific bit(s)
A lot of functions define their input arguments as flags in bit fields.
Of course, they could be substituted by a set ofbool-typed variables, but it is not frugally.