GENERAL: AUTOMATIC GENERATION OF LOOKUP TABLES
Information in this article applies to:
I am trying to write some code to automatically generate sin, cos and tan look-up tables for me. In order to test this method am declaring a global variable as:
double x = sqrt(2);
Yet it gives me an error, basically stating that the scalar initializer is not a constant expression. I have seen other C compilers accept this, so how do I do it?
Part 6.5.7 of the 1990 ISO C Standard states that "All the expressions in an initializer for an object that has static storage ... shall be constant expressions."
Part 6.4 of the 1990 ISO C Standard states that "Constant expressions shall not contain assignment, increment, decrement, function-call, or comma operators ..." and that "A constant expression can be evaluated during translation rather than runtime ...".
Therefore, if another C compiler allows double x = sqrt(2); when declaring a global variable, it is not behaving with full ANSI compliance.
There are several ways to solve this problem.
You could declare your look-up table as a global array/structure/whatever and in the main function initialize all the values using for loops. Some form of debugging method could then be used to extract the initialized table, or alternatively transmit it out of the serial port to a terminal program where you can "capture" it.
An easier solution is to write a PC DOS C program to do the same thing and output the initialized table to a text file in the form of a C array/structure/whatever declaration. You can then add that file to your C166 project.
Last Reviewed: Wednesday, November 7, 2001
of your data.