RE: C++ Compiling Problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On Sun, May 22, 2005 at 02:48:20PM +0200, Coert Waagmeester wrote:
> > I've started learning C++. (Should I first learn C ?)
>
> You can learn C++ directly, and if you're interested in learning good C++,
> there's some reasons to suggest doing it that way. C is a very elegant and
> uncomplicated language. C++ is a different story.
>
> However, if you're basically new to programming, your life will
> probably be
> easier if you *start* with working with an object oriented appoach to
> programming. A *lot* of C++ code out there is actually an ugly
> mix of core C
> with some C++ constructs glommed on. Modern C++ shouldn't be like
> that, and
> in fact all of this ...
>
> > I have an eBook from SAMS Teach yourself C++ in 21 days
> > When I compiled their Hello World example:
> >
> > 1: #include <iostream.h>
> > 2:
> > 3: int main()
> > 4: {
> > 5:    cout << "Hello World!\n";
> > 6:        return 0;
> > 7: }
> >
> > g++ came back with:
> > In file included from
> /usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2
/backward/iostream.h:31,from hello.cpp:1:
> >
> /usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2
/backward/backward_warning.h:32:2: warning:
> > #warning Thisfile includes at least one deprecated or
> antiquated header. Please consider using one of the 32 headers
> > found in section 17.4.1.2 of the C++ standard. Examples include
> substituting the <X> header for the <X.h> header for C++ includes,
> > or <iostream> instead of the deprecated header <iostream.h>. To
> disable this warning use -Wno-deprecated.
>
> ... is *exactly* that issue -- iostream.h is the older, more-C-like header
> file, and instead, you want the one called just iostream, with no
> extension.
>
> Basically, sounds like you need a newer book.
>
> I've checked out many of the C++ books out there, and the one I recommend
> above all others is Object-Oriented Programming in C++ (4th Edition) by
> Robert Lafore. (The current edition is also from SAMS -- older ones were
> published by The Waite Group.)
>
> It's *really* well written, and perhaps more importantly, very well
> structured for learning.
>
>
> > But the a.out file that gets created, does work, and
> > gives Hello World! on the console.
> > Should I worry about this warning?
>
> Yes. :)
>
> > They also say in the eBook that I still need to run the
> 'linker' on the file that is compiled,
> > but the a.out file already works? When I ran 'ld a.out' it did
> not work anymore.
> > Why do I not need to run the linker?
>
> Because you're using GCC, which also includes a linker, and in fact will
> default to doing the linking stage unless you use the -c flag to stop it.
>
> And even cooler, under GNU make (which you have in Fedora Core),
> if you have
> a program named "helloworld.cpp", you can just type "make
> helloworld" (from
> a prompt in the same directory), and it'll automatically call gcc with the
> right flags to generate an executable named "helloworld". (And will print
> out what it's doing.)
>
> PS: if you want a book on C instead of C++, don't bother with anything but
> the original book by the language's creators: C Programming Language by
> Brian Kernighan and Dennis Ritchie. As I said before, C is an elegant and
> small language, and this book is all you need. (Although you may also want
> to pick up The UNIX Programming Environment by Kernighan and Rob Pike.)
>
> --
> Matthew Miller           mattdm@xxxxxxxxxx        <http://www.mattdm.org/>
> Boston University Linux      ------>                <http://linux.bu.edu/>
> Current office temperature: 73 degrees Fahrenheit.


Well, you will find that everyone has an opinion on where to start, and you
will get a lot of different ones too.  I am currently a computer science
major on my last semester of school, and I would recommend learning C first.
We started with Java early, because Java is a very straight forward OOP
programming language.  C++ is certainly more flexible, but this can create
some issues for new programmers.

Here are some of the reasons I recommend C:

- C is the primary programming language of both Linux and Windows operating
systems.

- C is the basis for languages such as C++, Java, C#, and many others.

- You will learn all of the basic constructs with C as with any other
language.

- Once you have learned all of the basics, you can take it to the next
level, Object Oriented Programming in C.  Up to this point most everything
is straight forward with the exception of function pointers, structures,
unions, and enumerations.

- With OOP in C, you will construct objects through structures in header
file definitions.  This is not so elegant, but I can promise that you'll be
a much better programmer for learning OOP this way.

- In addition there are many tools that interface with C that are available
under Linux.  lex and yacc are two useful ones.  lex is very powerful for
pattern matching, and you can build your own compiler tools with yacc.

- You'll have to take all of the recommendations from everyone and make the
decision on your own.

Here are some books I recommend for C:

The Complete Reference C (latest edition), Schildt
	excellent for beginners and intermediate C programmers

The C Programming Language, Kernighan - Ritchie
	an excellent reference, but not so good for beginners

Advanced Programming in the UNIX Environment, Stevens
	good for Linux/Unix system programming

You can find tons of lex and yacc examples on-line.

If you want to start with an easy OOP, start with Java or C#.

Good luck!!!


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux