declaring defines.

Eize Oosting eoo at let.rug.nl
Fri Jun 21 23:59:17 AEST 1991


In article <SVEN.91Jun15175330 at laverne.cs.widener.edu> sven at cs.widener.edu (Sven Heinicke) writes:
>
>Hi, I got this to work no problem:
>
>#include <stdio.h>
>#define TRY "look","at","this",NULL
>main()
>{
>  char *first[] = {TRY};
>  int i;
>  for(i = 0;first[i] != NULL;i++)
>    printf("%s\n",first[i]);
>}
>
>That works fine.
>This does not work, is there any way to get something like this to compile?
>
>#include <stdio.h>
>#define TRY {"look","at","this",NULL},{"and","this","too",NULL}
>main()
>{
>  char *first[][] = {TRY};
>.  .  .
>}
>

You are very lucky that your compiler compiled you first program, because it
is not usual to be able to auto-initialise arrays. I think your compiler has
a way around with the first program, however the second program would use a
more complex  initialisationroutine. I think that's way it fails to compile.

It is, however, no problem if you make the declarations global or static.
But then they are initialised only once, not each time the function is entered.


  /\__________/\   /\___________________________________________________/\
 /              \ /                                                       \
|   Letteren-    |  Marvin Minsky once defined Artificial Intelligence as: |
|   Faculteit    |   '... the science of making machines do things that    |
| R.U. Groningen |   would require intelligence if done by men'.           |
| The Netherlands|                                                         |
|                |  Does this include formatting a floppy?                 |
| eoo at let.rug.nl |                                           Eize Oosting  |
 \  __________  / \  ___________________________________________________  /
  \/          \/   \/                                                   \/



More information about the Comp.lang.c mailing list