home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16162 < prev    next >
Encoding:
Text File  |  1992-11-12  |  1.4 KB  |  47 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!stanford.edu!unixhub!redwing.SLAC.Stanford.EDU!kelsey
  3. From: kelsey@redwing.SLAC.Stanford.EDU (Mike Kelsey)
  4. Subject: Re: Bad 'for' statement?
  5. Message-ID: <BxM32o.6EI@unixhub.SLAC.Stanford.EDU>
  6. Keywords: AT&T for
  7. Sender: news@unixhub.SLAC.Stanford.EDU
  8. Organization: Stanford Linear Accelerator Center
  9. References:  <1992Nov12.160420.18097@rs6000.bham.ac.uk>
  10. Date: Thu, 12 Nov 1992 16:27:59 GMT
  11. Lines: 34
  12.  
  13. In article <1992Nov12.160420.18097@rs6000.bham.ac.uk>, pickerig@eee.bham.ac.uk (Mr. G. Pickering) writes:
  14. |> Hi,
  15. |> 
  16. |> Could you tell me if this is really a syntax error as AT&T 2.1 reports?
  17. |> 
  18. |>   for(int i=0, int j=10;   i<10;   i++, j++)
  19. |>   {
  20. |>     // do something
  21. |>   }
  22.  
  23. Yes it is.  GCC 2.3.1 also calls it an error, claiming that the function 'j' is
  24. undeclared. You can fix it by eliminating the second 'int', since the comma in
  25. that construction does it for you.  Here is a complete sample program:
  26.  
  27. #include <stdio.h>
  28. int main()
  29. {
  30.   for (int i=0, j=10; i<10; i++, j++)
  31.     printf("\n i=%d, j=%d",i,j);
  32. }
  33.  
  34. |> 
  35. |> Thanks,
  36. |> 
  37. |> Guy
  38.  
  39. You're welcome. :-)
  40.                         -- Mike Kelsey
  41. -- 
  42. [  My opinions are not endorsed by SLAC, Caltech, or the US government  ]
  43. "I've seen things you people wouldn't believe.  Attack ships on fire off
  44. the shoulder  of Orion.   I've watched  C-beams glitter in  the darkness
  45. near the Tannhauser Gate.  All these memories will be lost in time, like
  46. tears in the rain."  -- Roy Batty
  47.