public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: GCC Compile Failure
@ 2006-07-09  1:06 Bill McEnaney
  0 siblings, 0 replies; 8+ messages in thread
From: Bill McEnaney @ 2006-07-09  1:06 UTC (permalink / raw)
  To: jjdevine, gcc-help

Hi, John,

Why not include iostream.h instead of glibc?" Glibc isn't a header file.
 Since the iostream,h header file defines cout, you can delete the line
that says that cout is a void function.  Hope this helps, my good guy.

Bill

> Hello GCC Helpers,
> 
> This is a program I wrote:
> 
> #include <glibc>
> #include <stdio.h>
> void cout();
> main()
> {printf "Hello World. /n";
> 	cout << "Hello/n";
> return 0;
> }
> 
> The "make" command gave me:
> 
> gcc  -o simplest simplest.c
> error: glibc: no such file or directory
> error: invalid operands to binary <<
> make: *** [simplest] Error 1
> 
> What's wrong?  Books I have show that "<<" works fine sending output
to the 
> monitor!
> 
> If I comment out both the cout and #include <glibc> the printf works fine 
> after doing a make.
> 
> I'm using SUSE Linux 10.1 on an HP Pavilion, 165 MB HD, 512 MB RAM,
AMD 3000+.
> 
> Thanks for any help.
> 
> John J. Devine
> 
> 

________________________________________________________________
"Pro-choice?"  Then click here.
http://cathinsight.com/morality/saying.htm

"Men must look for the peace of Christ in the Kingdom of Christ... When
once men recognize, both in private and in public life, that Christ is
King, society will at last receive the great blessings of real liberty,
well-ordered discipline, peace and harmony."  Pope Pius XI

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: GCC Compile Failure
  2006-07-08 20:18 jjdevine
  2006-07-08 21:06 ` Artūras Moskvinas
@ 2006-07-10 14:55 ` Young, Michael
  1 sibling, 0 replies; 8+ messages in thread
From: Young, Michael @ 2006-07-10 14:55 UTC (permalink / raw)
  To: jjdevine, gcc-help

Welcome to C++!
I know this is a gcc maillist and not one for C++ specifically, but I'm going to clarify things using the C++ standard.  I highly recommend you get a copy of this and get used to referencing it - it's heady stuff, and overwhelming at first (and for some time afterward), but it is the standard and can steer you clear of a LOT of "well-intentioned-but-bad" advice available on the web and in forums.  To help you sort through things from a practitioner's (rather than "language lawyer") perspective, there are a few good references - I use C++ Primer (now in 4th ed., by Lippman, Lajoie, and Moo) most often.

As was previously pointed out, cout is an object, not a function.  You need to "#include <iostream>" to pick up the definition - see C++ Std - 27.3.  As was also pointed out, C++ std library include files don't have an extension (officially, again, certain implementations continue to support legacy, non-standard extensions).  (C++ Std. 17.4.1.2)

In addition, although it will work with "#include <stdio.h>", I'd recommend using "#include <cstdio>" and change the printf to std::printf.  (Or simply declare "using namespace::std;" and drop all the "std::" prefixes.  When you get a chance, you may want to look at "namespaces" in a good C++ reference.
See appendix D - D.5 in the C++ std and section 17.4.1.2 for details.

Finally, as a good programming practice, do not rely on the "implicit int return" - declare main as "int main( )".  BTW - you may see a lot of examples out there with different prototypes/signatures for main - there are only two "official" signatures for this function (and "int main( )" is one of them) - see C++ Std - 3.6.1 paragraph 2.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: GCC Compile Failure
@ 2006-07-09  2:35 Bill McEnaney
  0 siblings, 0 replies; 8+ messages in thread
From: Bill McEnaney @ 2006-07-09  2:35 UTC (permalink / raw)
  To: gcc-help, gcc-help

Brian is right.  I forgot to type the ".h"

Bill

> Bill McEnaney wrote:
> 
> > Sunblade 100 workstation that runs gcc-4.1.1.  The C++ compiler, g++,
> > warned me that iostream had been deprecated.  That's why I don't know
> 
> No, it warned you that <iostream.h> is deprecated and should not be
> used, not <iostream> (which is the proper header to use, without the
> .h). 
> <http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4>
> 
> Brian
> 
> 

________________________________________________________________
"Pro-choice?"  Then click here.
http://cathinsight.com/morality/saying.htm

"Men must look for the peace of Christ in the Kingdom of Christ... When
once men recognize, both in private and in public life, that Christ is
King, society will at last receive the great blessings of real liberty,
well-ordered discipline, peace and harmony."  Pope Pius XI

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: GCC Compile Failure
  2006-07-09  1:24 Bill McEnaney
  2006-07-09  1:55 ` Brian Dessent
@ 2006-07-09  2:00 ` David Fang
  1 sibling, 0 replies; 8+ messages in thread
From: David Fang @ 2006-07-09  2:00 UTC (permalink / raw)
  To: Bill McEnaney; +Cc: jjdevine, gcc-help

> Hi, again, John,
>
> You need to parenthesize printf's argument, too, so your printf should
> look more like this:
>
> printf ("Hello, world.\n");
>
> After I solved that problem, I compiled your program and ran it on my
> Sunblade 100 workstation that runs gcc-4.1.1.  The C++ compiler, g++,
> warned me that iostream had been deprecated.  That's why I don't know
> what header file you need to include instead of iostream.h.  The warning
> said that I could suppress it with a compiler directive, but I think
> it's better to include the header file meant to replace iostream.h  By
> the way, I'm not a C++ programmer.


1) That header would be <iostream>.
(When in doubt, drop the .h from old C++-header includes.)

2) The 'cout' ostream resides in the std:: namespace:
I suggest:

	using std::cout;
or
	using namespace std;

somewhere before main, otherwise, every reeference to cout will need to be
prefixed as "std::cout".

3) In Standard C++, main() must return an int, e.g.:

	int
	main(int argc, char* argv[]) { ... }

I wouldn't rely on the old C-like behavior of implicit return type (int).

> > Hello GCC Helpers,
> >
> > This is a program I wrote:
> >
> > #include <glibc>
> > #include <stdio.h>
> > void cout();
> > main()
> > {printf "Hello World. /n";
> > 	cout << "Hello/n";
> > return 0;
> > }

Fang

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: GCC Compile Failure
  2006-07-09  1:24 Bill McEnaney
@ 2006-07-09  1:55 ` Brian Dessent
  2006-07-09  2:00 ` David Fang
  1 sibling, 0 replies; 8+ messages in thread
From: Brian Dessent @ 2006-07-09  1:55 UTC (permalink / raw)
  To: gcc-help

Bill McEnaney wrote:

> Sunblade 100 workstation that runs gcc-4.1.1.  The C++ compiler, g++,
> warned me that iostream had been deprecated.  That's why I don't know

No, it warned you that <iostream.h> is deprecated and should not be
used, not <iostream> (which is the proper header to use, without the
.h). 
<http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4>

Brian

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: GCC Compile Failure
@ 2006-07-09  1:24 Bill McEnaney
  2006-07-09  1:55 ` Brian Dessent
  2006-07-09  2:00 ` David Fang
  0 siblings, 2 replies; 8+ messages in thread
From: Bill McEnaney @ 2006-07-09  1:24 UTC (permalink / raw)
  To: jjdevine, gcc-help

Hi, again, John,

You need to parenthesize printf's argument, too, so your printf should
look more like this:

printf ("Hello, world.\n");

After I solved that problem, I compiled your program and ran it on my
Sunblade 100 workstation that runs gcc-4.1.1.  The C++ compiler, g++,
warned me that iostream had been deprecated.  That's why I don't know
what header file you need to include instead of iostream.h.  The warning
said that I could suppress it with a compiler directive, but I think
it's better to include the header file meant to replace iostream.h  By
the way, I'm not a C++ programmer.

Bill

Hi, John,

Why not include iostream.h instead of glibc?" Glibc isn't a header file.
Since the iostream,h header file defines cout, you can delete the
linethat says that cout is a void function.  Hope this helps, my good guy.

Bill

> Hello GCC Helpers,
> 
> This is a program I wrote:
> 
> #include <glibc>
> #include <stdio.h>
> void cout();
> main()
> {printf "Hello World. /n";
> 	cout << "Hello/n";
> return 0;
> }
> 
> The "make" command gave me:
> 
> gcc  -o simplest simplest.c
> error: glibc: no such file or directory
> error: invalid operands to binary <<
> make: *** [simplest] Error 1
> 
> What's wrong?  Books I have show that "<<" works fine sending output
to the 
> monitor!
> 
> If I comment out both the cout and #include <glibc> the printf works fine 
> after doing a make.
> 
> I'm using SUSE Linux 10.1 on an HP Pavilion, 165 MB HD, 512 MB RAM,
AMD 3000+.
> 
> Thanks for any help.
> 
> John J. Devine
> 
> 

________________________________________________________________
"Pro-choice?"  Then click here.
http://cathinsight.com/morality/saying.htm

"Men must look for the peace of Christ in the Kingdom of Christ... When
once men recognize, both in private and in public life, that Christ is
King, society will at last receive the great blessings of real liberty,
well-ordered discipline, peace and harmony."  Pope Pius XI




________________________________________________________________
"Pro-choice?"  Then click here.
http://cathinsight.com/morality/saying.htm

"Men must look for the peace of Christ in the Kingdom of Christ... When
once men recognize, both in private and in public life, that Christ is
King, society will at last receive the great blessings of real liberty,
well-ordered discipline, peace and harmony."  Pope Pius XI

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: GCC Compile Failure
  2006-07-08 20:18 jjdevine
@ 2006-07-08 21:06 ` Artūras Moskvinas
  2006-07-10 14:55 ` Young, Michael
  1 sibling, 0 replies; 8+ messages in thread
From: Artūras Moskvinas @ 2006-07-08 21:06 UTC (permalink / raw)
  To: jjdevine; +Cc: gcc-help


> Hello GCC Helpers,
> 
> This is a program I wrote:
> 
> #include <glibc>
> #include <stdio.h>
> void cout();
> main()
> {printf "Hello World. /n";
> 	cout << "Hello/n";
> return 0;
> }
> 

cout is not a function, it is an object. You can't declare it like this.
Second, you wrote C++ code, and you are compiling it using C compiler
(use g++ command instead of gcc). Third there is no such library glibc,
I think you meant stdlib.h. The correct code might look like this:

#include <iostream>
#include <stdio.h>
int main()
{
   printf("Hello World. \n");
   std::cout << "Hello\n";
   return 0;
}

Arturas M.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* GCC Compile Failure
@ 2006-07-08 20:18 jjdevine
  2006-07-08 21:06 ` Artūras Moskvinas
  2006-07-10 14:55 ` Young, Michael
  0 siblings, 2 replies; 8+ messages in thread
From: jjdevine @ 2006-07-08 20:18 UTC (permalink / raw)
  To: gcc-help

Hello GCC Helpers,

This is a program I wrote:

#include <glibc>
#include <stdio.h>
void cout();
main()
{printf "Hello World. /n";
	cout << "Hello/n";
return 0;
}

The "make" command gave me:

gcc  -o simplest simplest.c
error: glibc: no such file or directory
error: invalid operands to binary <<
make: *** [simplest] Error 1

What's wrong?  Books I have show that "<<" works fine sending output to the 
monitor!

If I comment out both the cout and #include <glibc> the printf works fine 
after doing a make.

I'm using SUSE Linux 10.1 on an HP Pavilion, 165 MB HD, 512 MB RAM, AMD 3000+.

Thanks for any help.

John J. Devine

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-07-10 14:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-09  1:06 GCC Compile Failure Bill McEnaney
  -- strict thread matches above, loose matches on Subject: below --
2006-07-09  2:35 Bill McEnaney
2006-07-09  1:24 Bill McEnaney
2006-07-09  1:55 ` Brian Dessent
2006-07-09  2:00 ` David Fang
2006-07-08 20:18 jjdevine
2006-07-08 21:06 ` Artūras Moskvinas
2006-07-10 14:55 ` Young, Michael

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).