During definition:

int a[] = {1,2,3,4};

Creates an "array", referenced by a, of 4 integers.
In this case, the size will be automatically discovered.
(There are other tricks that can be done, especially when a size is
specified, please see a good C reference.)

For later processing (such as when things are not know at
compile-time), do things manually.
(Also see memset, wmemset, maybe...)

int a[4];
int i;
for (i = 0; i < 4; i++)
  a[i] = i;

You can also determine the size of the array using:

int size_of_a = sizeof(a)/sizeof(a[0]);

and then use size_of_a instead of 4, above, if it makes your life easier.
Generally, I'd say it'd be better to just use a size define unless the
size of the array is automatically computed, as in the first example.

HTH,
Paul

On Thu, Jul 24, 2008 at 3:19 AM, milos rovcanin <[EMAIL PROTECTED]> wrote:
> Ok,i would like to ask you one question: how to initialize an array???  I am
> using the GCC linux compiler.
>
> if i do it like this: a[1,1,1,1,1,1,1,1]
>   compiler says " parse error before ',' "  i used to compile the same
> program in Cygwin and there were no errors like this. Where is the problem?
> Someone,please,help me!
>
> _______________________________________________
> Tinyos-help mailing list
> Tinyos-help@millennium.berkeley.edu
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to