paolo <> wrote:
> Please excuse my very poor English, I hope you understand my question.
> I want to create a readonly array of data, then a readonly array of a
> structure (STRUCT). This is data I access but I want it protected against
> accidental change. The following is my test code.
> #include "stdafx.h"
> struct LVC
> {
> unsigned short int lo;
> unsigned short int hi;
> };
> void main()
That should be
int main( void )
(main() is supposed to retur an int and take either no arguments
or an int and an array of char pointers, but not an unsoecified
number of arguments).
> {
> //This seems to work
> static const unsigned short int LV[4] =
> {0xAC00,cd TE
> 0xAC1C,
> 0xAC38,
> 0xAC54 };
What is the 'static' meant to be good for? Also without
it this will create an array that is read-only. 'static'
only is necessary if you want a variable that "survives"
the end of the function and thus still exists (with the
previous value) when you call the function another time.
> //THIS DOESN'T WORK. COMPILER COMPLAINS
> static const struct LVC[4] = {
The problem is that this should be something like
const struct LVC some_name[ 4 ] = {
and then the compiler should accept it. That's because
the type is 'struct LVC' and you're creating a strange
mix out of the type name and the variable name.
> { 0xAC01, 0xAC1B },
> { 0xAC1D, 0xAC37 },
> { 0xAC39, 0xAC53 },
> { 0xAC55, 0xAC6F },
> };
> I use Microsoft Visual C++ Express Edition
I hope you use it as a C and not a C++ compiler, otherwise
you'd better ask in comp.lang.c++.
> (I also would like to get rid of that #include "stdafx.h" if
> there is some compiler configuration that will allow me
> to do that.)
There's nothing in the program you psoted that would require
the inclusion of any header files.
Regards, Jens
--
\ Jens Thoms Toerring ___
\__________________________
http://toerring.de