home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: Problem with CC 3.0
- Message-ID: <9224516.3803@mulga.cs.mu.OZ.AU>
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- References: <moharil.715318065@judy.cs.iastate.edu>
- Date: Tue, 1 Sep 1992 06:04:31 GMT
- Lines: 53
-
- moharil@cs.iastate.edu (Vinay Arvind Moharil) writes:
-
- >Hi Netters!
- >I am new to the world of C++. I am trying to use the CC 3.0 for Sun SPARC.
- >Here is the code in C and C++. The code in C can be compiled with the C
- >compiler happily without any problems. However when I try to compile the
- >C++ code using CC 3.0 I get lot of errors in the files like sys/stat.h,
- >X11/Intrinsic.h. I did the extern "C" ... part because some one suggested that
- >as a solution to get rid of the syntax errors (in the X11/Intrinsic.h file) I
- >was facing. In my opinion, The CC 3.0 should compile the #include portion as a
- >C code and should not give errors as is the case with the C compiler.
-
- [C code omitted]
-
- >main(argc,argv)
- >int argc;
- >char *argv[];
- >{
- >extern "C" {
- >#include <X11/Intrinsic.h>
- >#include <stdio.h>
- >}
- >typedef char *String1;
- >String1 xyz;
- >printf("Hi!\n");
- >}
-
- Header files should only be #included at file scope, ie. not within
- a function. You need to move the #include statements to before the
- start of main().
-
- You should also define main() using a prototype - the old K&R style
- of function definition is obsolete. Try the following:
-
- extern "C" {
- #include <X11/Intrinsic.h>
- #include <stdio.h>
- }
-
- typedef char *String1;
-
- int main(int argc, char *argv[])
- {
- String1 xyz;
- printf("Hi!\n");
- return 0;
- }
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature virus is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-