Skip to content

Defining value of array elements when dimensioning array

Question

I am having trouble defining the value of array elements when I dimension an array in CCL. What is the syntax for doing this?

Synopsis

Defining the value of array elements when dimensioning array

Symptoms

Perhaps the best way to approach this problem is by way of example: Let's assume that you want to dimension a real variable array with 5 elements (0 through 4) and you want to set the value of the array elements at the time you dimension the array. In the C programming language, the syntax would be:
  real pupil_height[5] = {2.1, 2.2, 2.3, 2.4, 2.5};
But if you write this within your CCL program and try to compile it, you will get an error message.

Solution

You can solve the problem in the above example using either one of two methods:
  1. Move the array definition outside the CCL program where it becomes a global array definition.
  2. Mark the variable array as "protected" using the "static" moniker: static real pupil_height[5] = {2.1, 2.2, 2.3, 2.4, 2.5};
Both these approaches ensures that the variable array cannot be re-defined later.