EETimes

Embedded Systems December 2000 Vol13_13

Issue link: http://dc.ee.ubm-us.com/i/71850

Contents of this Issue

Navigation

Page 159 of 197

the return value of daaO. It contains the poin ter, that when adjusted by the ini tial dimension first subscript-O, -1 , and -25 in our three cases-points to the fi rst poin ter inside the daaO allo- cated block of poin ters to pointers. Arr points to &arr[QJ(Ox00021f68), which conta ins pointe r arr[O] (Ox00021 fS4) pointing to the second eleme nt in the data area, &arr[Q][Q] (Ox00021fS4), which is the middle of the first subarray of data subscripted by the second subscript (running fmm -1 to 1). Since the sec- ond subscript begins with - 1, indexing o ne element previous gives the loca- U S Software Knows Why CAD-UL is #1. U S Software knows who to count on when they need a partner for x86 embedded development tools. And it looks like they're not alone. According to VOC, CAO-UL is the number one revenue generator of x86 embedded development tools worldwide. tion &arr[Q][ - 1 ] (Ox00021 fSo) which contains - 1 (0 + - 1 = -1 ). Since an ele- ment is four bytes, the addresses are adjusted by fo ur bytes for eve ry change of one in subscl-ip t. The sec- ond element of the first subsc ript, arr[1 ], stored at &arr[1](Qx00021f6C), poin ts to &arr[1][Q](Ox00021f60), the fifth element of Ule data area, the mid- dle of Ule second subarray of data sub- scripted by the second subscript. The decimal values of the data are in parenthesis at the right. Why does the location Ox00021f70 have a ze ro in it? I mentioned earl ier that if the data area ended o n a boundary that was not a pointer boundary, the addresses of the pointer area wo uld have to be adjusted to word-align all pointers. In th is case, the pointers did not need different alignment, so the extra allo- cated space shows up at the end. Stare at th is for awhile, but not too lo ng, ul en examine B. Examine B This case is only di fferent in the start- ing subscript of the first dimension-it begin at -1 instead of O. ar r now poin ts to &arr[O] (Ox00021f6C), which when indexed by -1 , gives the address &a r r[- 1](Ox00021f68), the same place as last time. From here on th e pointers are identical to case A. The trick is where arr points to after being adjust- ed by the tarting subscript for the first dimension . Since the basic poin ter adjust uni t is one integer, adjusting by -1 means subractin g four bytes (Ox00021 f6c - 4 = Ox00021 f68 ). ~ U S SOPTWARE. . EM BED D E D EXCELLE N CE • Real-Time Operating System • Embedded TCP/IP Protocol Suite • Embedded File System • Distributed Computing www.ussw.com (800) 356-7097 CAI)-UL • C/C++ x86 Compiler Systems • Symbolic Debugging Systems • IDE: CAD-UL Workbench • Code Coverage Tools www.cadul.com (877) GO CAD-UL Examine C Again, this case is o ny different in the starting subscript, but wi th a more extreme -25 offset. arr now points to &arr[Q](Ox00021fcc) which is entirely outs ide the allocated space. When this allocated space is indexed by - 25, it poin ts to &a rr[ -2S] (Qx00021f68), the same location as the other cases, and leading to the same values. That is, - 25x4 = -100(d ) = - 64(h ), a nd Ox0002lfcc - 64 = Ox0002lf68. No memo ry violation should occur if valid 158 DECEMBER 2000 Embedded Systems Programming

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems December 2000 Vol13_13