home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13130 < prev    next >
Encoding:
Text File  |  1992-08-31  |  1.9 KB  |  65 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  3. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: Problem with CC 3.0
  5. Message-ID: <9224516.3803@mulga.cs.mu.OZ.AU>
  6. Sender: news@cs.mu.OZ.AU
  7. Organization: Computer Science, University of Melbourne, Australia
  8. References: <moharil.715318065@judy.cs.iastate.edu>
  9. Date: Tue, 1 Sep 1992 06:04:31 GMT
  10. Lines: 53
  11.  
  12. moharil@cs.iastate.edu (Vinay Arvind Moharil) writes:
  13.  
  14. >Hi Netters!
  15. >I am new to the world of C++. I am trying to use the CC 3.0 for Sun SPARC.
  16. >Here is the code in C and C++. The code in C can be compiled with the C 
  17. >compiler happily without any problems. However when I try to compile the
  18. >C++ code using CC 3.0 I get lot of errors in the files like sys/stat.h,
  19. >X11/Intrinsic.h. I did the extern "C" ... part because some one suggested that
  20. >as a solution to get rid of the syntax errors (in the X11/Intrinsic.h file) I 
  21. >was facing. In my opinion, The CC 3.0 should compile the #include portion as a 
  22. >C code and should not give errors as is the case with the C compiler.
  23.  
  24. [C code omitted]
  25.  
  26. >main(argc,argv)
  27. >int argc;
  28. >char *argv[];
  29. >{
  30. >extern "C" {
  31. >#include <X11/Intrinsic.h>
  32. >#include <stdio.h>
  33. >}
  34. >typedef char *String1;
  35. >String1 xyz;
  36. >printf("Hi!\n");
  37. >}
  38.  
  39. Header files should only be #included at file scope, ie. not within
  40. a function. You need to move the #include statements to before the
  41. start of main().
  42.  
  43. You should also define main() using a prototype - the old K&R style
  44. of function definition is obsolete. Try the following:
  45.  
  46.     extern "C" {
  47.     #include <X11/Intrinsic.h>
  48.     #include <stdio.h>
  49.     }
  50.  
  51.     typedef char *String1;
  52.  
  53.     int main(int argc, char *argv[])
  54.     {
  55.         String1 xyz;
  56.         printf("Hi!\n");
  57.         return 0;
  58.     }
  59.  
  60. -- 
  61. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  62. This .signature virus is a self-referential statement that is true - but 
  63. you will only be able to consistently believe it if you copy it to your own
  64. .signature file!
  65.