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