views:

85

answers:

4

I have an "array" of bytes that is referenced in some high-level client/developer documentation (which does not contain any programming language or environment specific information). In this document, bytes are currently referred to as "byte 3" or "byte 17", etc. The development environment is C/C++ and the bytes are stored in an array in which the starting index is 0 (naturally).

The problem is that developers may (have) interpreted "byte 3" in the document as meaning either myarray[3] or myarray[2].

What kind of terminology do folks use to make the "byte number" vs. "array index" distinction clear, yet keep it readable to both (non-programmer) clients and developers?

+4  A: 

What kind of terminology do folks use to make the "byte number" vs. "array index" distinction clear, yet keep it readable to both (non-programmer) clients and developers?

Array indices start at 0. (Or, 1. Take a stance and state it in your design document.)

dirkgently
And if the array index doesn't match the byte number, throw in a nice comment where myarray[] is defined.
Joel Rondeau
+1 - If you risk multiple interpretations, mitigate the risk by explicitly stating it in the document.
bstpierre
A: 

Check in the documentation if exists a "byte 0".

Didier Trosset
+4  A: 

One possibility is to just directly state where you're starting counting. Another possibility is to use things like "first byte", "seventeenth byte", and so on. A third (the one I usually prefer) is to speak in terms of offsets from the base address.

Jerry Coffin
+1 for offset from base address
atzz
I like this, or at least a variation of it. "First", "second", etc. does seem to be interpreted by most as referring to a sequence starting at "1". I think a combination of terms would work well, something like "the 1st byte of the serial number (serial_num[0]) will be used...".
craigh
+1 for just directly stating it. Sometimes the easiest way to eliminate all possible confusion is just to explicitly state things.
TheUndeadFish
+2  A: 

You could remove all reference to the position in the array from your documentation.

Give things a meaningfull name.

Then have constants in your program that map the name to a position in the array.

Shiraz Bhaiji