Boost logo

Boost Users :

From: Merrill Cornish (merrill.cornish_at_[hidden])
Date: 2005-08-07 07:54:18


>>> the places where you would use fixed arrays,
>>> you probably also know at what indexes certain data resides.

If you use fixed arrays in that way, then you are using them much like structs where, say, [0] mean THIS and [1] means THAT and [2] means something else etc. If that were the case, then individually named variables would likely work better.

The more common reason for fixed arrays is that the array is matching something in the real world: I'm doing a 256 element Fast Forier Transform, I'm processing census data for 50 US states, I'm tallying sales for the 12 months.

Even if you can attach a specific meaning for individual elements, most of the processing is still done either by iterating over the array or by accessing an element based on an index number extracted from incoming data.

In general rogramming the occassions where you would be accessing the array by a constant index is still very rare compared to accessing the elements by a variable index.

Even if you did have an application where almost all of the array accesses were with constant indexes, then you would also certainly create a set of constants so that you would, say, extract the state name from an array of address strings by saying [WYOMING] rather than [49]. You set the constants up once and you're done. No more array bounds access errors. Even if the initial set of constant definitions had an error, once fixed, it's fixed forever.

Again, the number of places where checking array bounds on fixed length arrays is too small to justify work involved.

Merrill


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net