home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20112 < prev    next >
Encoding:
Internet Message Format  |  1993-01-23  |  2.2 KB

  1. Path: sparky!uunet!mcsun!sun4nl!and!jos
  2. From: jos@and.nl (Jos Horsmeier)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Few simple questions
  5. Message-ID: <4393@dozo.and.nl>
  6. Date: 23 Jan 93 13:05:25 GMT
  7. References: <1993Jan21.001022.46578@kuhub.cc.ukans.edu> <1993Jan22.225219.18959@ringer.cs.utsa.edu>
  8. Organization: AND Software BV Rotterdam
  9. Lines: 44
  10.  
  11. In article <1993Jan22.225219.18959@ringer.cs.utsa.edu> pnarsipu@ringer.cs.utsa.edu (Praasad Y. Narsipur) writes:
  12. |In article <1993Jan21.001022.46578@kuhub.cc.ukans.edu> kugold@kuhub.cc.ukans.edu writes:
  13. |>
  14. |>3. In C again, I want to initialize and array of integers, like
  15. |>   
  16. |>   main()
  17. |>   {
  18. |>     int ttime[6]={0,0,0,0,0,0}
  19. |>     /* rest of program */
  20. |>   }
  21. |>
  22. |>ccom: Error: tr.c, line 12: no automatic aggregate initialization
  23. |>        int     ttime[6]={0,0,0,0,0,0};
  24. |>      ------------------^
  25. |>      ---------------------^
  26. |>      -----------------------^
  27. |>      -------------------------^
  28. |>      ---------------------------^
  29. |>      -----------------------------^
  30. |>ccom: Error: tr.c, line 12: illegal lhs of assignment operator
  31. |>        int     ttime[6]={0,0,0,0,0,0};
  32. |>      -------------------------------^
  33.  
  34. |This looks perfect. This should probably u would have left something
  35. |in your program. This works for me. 
  36. |Try giving blanks between '0' and `,`.
  37.  
  38. That's not the issue here. The original poster (more than) probably
  39. uses a pre-ANSI C compiler. Good old K&R1 C doesn't allow initialization
  40. of automatic (or: local) arrays. And that's exactly what the compiler
  41. tells us (see above.) The compiler used above is a very silly compiler
  42. though, because it can signal a _semantic_ error (initialization of
  43. automatic arrays,) while there still is nothing wrong with the _syntax_
  44. of this particular program fragment. The compiler should have been
  45. capable of parsing the entire initializer (and ignoring it semantically)
  46. and start generating code again after the first semicolon. This compiler
  47. chose to do otherwise: it tried to convert the (illegal) initialization
  48. into some sort of assignment and goofed completely by emitting six (!)
  49. errors, one for every initializer. This, of course, causes a lot of
  50. confusion ...
  51.  
  52. kind regards,
  53.  
  54. Jos aka jos@and.nl
  55.