> In C (and other languages) arrays can be initialised using a
> list of numbers:
> 
> int a_1[10] = { 3, 3, 3, 3, 3, 3, 3, 3};

I agree with your statement that there is a problem with the above but
can not offer a solution to the problem you have stated.  However, most
people sidestep the issue by not over specifying -- which is what is
being done here:  there is a conflict between specifying the length of
the array and providing an initializer.  Excluding the "lazy" case of
initializing the first few of a larger array, most people would specify
either the size and not initialize of the initializer and not the size
-- the compiler does not use the size after allocating the storage.  So:

    int a_1[] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } ;

or

    int *const a_1 =  { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } ;

are the most likely occurrences of this sort of initialization.  The
size is then determined at compile time using the classic idiom:

    const int size = sizeof(a_1) / sizeof(int) ;


Russel.
======================================================================
Professor Russel Winder         Professor of Computing Science
Department of Computer Science  Fax: +44 20 7848 2851/+44 20 7848 2913
King's College London           [EMAIL PROTECTED]
Strand, London WC2R 2LS, UK     http://www.dcs.kcl.ac.uk/staff/russel/


- Automatic footer for [EMAIL PROTECTED] ----------------------------------
To unsubscribe from this list, mail [EMAIL PROTECTED]  unsubscribe discuss
To join the announcements list, mail [EMAIL PROTECTED] subscribe announce
To receive a help file, mail [EMAIL PROTECTED]         help
This list is archived at http://www.mail-archive.com/discuss%40ppig.org/
If you have any problems or questions, please mail [EMAIL PROTECTED]

Reply via email to