A Conversation for The H2G2 Programmers' Corner

can someone help an absolute beginner in c++?

Post 1

Researcher207975

...and I do mean absolute beginner. I can't even get my first obligatory 'hello' program to run! smiley - cry

I've posted a message up in the How Do I...? area of h2g2 before finding this mecca of programming.

Basically, I'm using the terminal on my mac (essentially unix) and I have written and (I believe) compiled my first c++ program... but I don't seem to be able to get it to run.

As I'm not sure how to put in a link to my previously posted question, I'll repeat the details here (hope you don't mind).

To compile I did this:
c++ hello.cpp -o hello

This created a file called hello

Then I thought all I had to do was type in hello, but to my dismay, it just said it couldn't find the command.

Please help me find my training wheels... smiley - smiley


can someone help an absolute beginner in c++?

Post 2

Ion the Naysayer

"hello" may not be set to execute permissions. Try "chmod 755 hello" in the same directory and try again.


can someone help an absolute beginner in c++?

Post 3

Ion the Naysayer

Another thought... If it still doesn't work, try "./hello" instead of just "hello". Depending on your configuration you may have to specify that the program is in the current directory.


can someone help an absolute beginner in c++?

Post 4

26199

Ion's second answer sounds right to me... as far as I'm aware it's a security precaution, stops you accidentally running a program that's not in one of the standard locations...

So -- if I might ask -- why programming, and why c++?

I wish you all the best with it, of course, programming is a lot of fun smiley - smiley... I'm just incurably curious smiley - biggrin


can someone help an absolute beginner in c++?

Post 5

Researcher207975

Thanks very much Ion & 26199! ./hello did the trick... I can now move on from Chapter 2 of the Idiot's Guide smiley - biggrin

As for why programming and why c++? Well, I got a taste of programming in uni (did java), sadly, I enjoyed it... Unfortunately, I'm one of those ppl who constantly struggles with themselves trying to discover their perfect career & as a result change my mind a lot...

I found a course in games programming that I'd like to do and I thought I'd dip my toe in the c++ pool before taking the plunge and forking out large sums of money for a course that uses visual c++.

Thanks again!


can someone help an absolute beginner in c++?

Post 6

DoctorMO (Keeper of the Computer, Guru, Community Artist)

Yep great work guys, same anwsers I would have given, so why c++, why not ansii c? all those type def's and castings, smiley - grr lots of display niggles and string manipulation problems, although visual c++ I didn't find as nice to work with as just gcc and kate.

I'm going to move onto Java at some point, now that I got that SmartBeans Thingy, looks quite nice.

-- DoctorMO --


can someone help an absolute beginner in c++?

Post 7

26199

Ah... I've been using Java at uni for ... well, a little over a year now smiley - smiley... good fun!...

I've never actually used C++ as such, only C... but as far as I'm aware it's effectively Java but not as restricted, and with a few extra bits (and a few things not done as well), and of course different libraries. You can screw things up much more thoroughly smiley - smiley... but it is indeed the industry standard for games programming.

Either way, have fun smiley - smiley... the programmer's corner is a good place to ask questions smiley - ok


can someone help an absolute beginner in c++?

Post 8

MaW

C++ is a bit more than a less restrictive Java... I always find it feels like a top-of-the-range sports car next to a family saloon.


can someone help an absolute beginner in c++?

Post 9

26199

smiley - nahnah


can someone help an absolute beginner in c++?

Post 10

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

I always thought the industry standard for games programming was Assembler? smiley - tongueout


can someone help an absolute beginner in c++?

Post 11

26199

Ah, those were the good old days...

Ever play anything by Epic MegaGames?... Epic Pinball, One Must Fall... those, apparently, were coded in pure Assembler.

Respect smiley - cool


can someone help an absolute beginner in c++?

Post 12

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

I recently aquired a book by the authors of "Quake", giving the secrets of their rendering engine. Everything that actually manipulated pixels was written in pure assembler; higher-level languages like C++ were only used to write the "user shell" that tied it all together. smiley - geek

Their polygonal texture-mapping routines were optimised to eight machine cycles per pixel! smiley - wow


can someone help an absolute beginner in c++?

Post 13

26199

Interesting...

Was that for the software rendering, though?...

I can't see hardware-based rendering being all that optimisable...

Besides, Quake was a top-of-the-range game... hardly standard... smiley - winkeye

What's the book? Any good?


can someone help an absolute beginner in c++?

Post 14

Ion the Naysayer

Authors of Quake - Just John Carmack? Or others as well? I'm insatiably curious. smiley - smiley


can someone help an absolute beginner in c++?

Post 15

MaW

John Carmack didn't work alone on Quake, but nobody ever seems to remember who the other people were.

C++ is used increasingly for more and more of games because computers are getting faster and this allows, rather than for them to be able to waste CPU cycles (which they can't), but rather to be able to use better and better compilers, because the compilers can do far more optimisation than before while still maintaining acceptable compile times.

I would imagine hand-tuning in assembler still happens of course, but not to the extent that it used to, especially when you're using hardware graphics rendering (written in OpenGL or Direct3D most likely).


can someone help an absolute beginner in c++?

Post 16

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

It was the "Graphics Programming Black Book" by Michael Abrash, with foreward and some sections by John Carmack. And yes, the 8 instruction cycles per pixel was for software texture mapping, on a VGA-compliant device, using a "classic" (non-MMX) Pentium CPU model! smiley - wow

The book was published in 2000, and recently given away free in PDF format to Byte.com subscribers. smiley - geeksmiley - ok


can someone help an absolute beginner in c++?

Post 17

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

(154MB download, fyi smiley - yikes)


can someone help an absolute beginner in c++?

Post 18

DoctorMO (Keeper of the Computer, Guru, Community Artist)

smiley - laugh Oh how none Assembler programers sqweel when it is mentioned, that asembler is fast, you may argue all you want, C or C++ isn't never going to be as fast. no mater how good your opermisations, anyway it probly gets worse with C#.

I belive all programers should learn some basic asm, even just x86 basics, it teaches you about some fundermental principals, like COMMENTING CODE! smiley - winkeye

Game Programing gets all the attenion these days. but it get's high up after a while, too many libaries and sub classes.

-- DoctorMO --


can someone help an absolute beginner in c++?

Post 19

Ion the Naysayer

Considering with C# there's a layer between the executable and the hardware, it most likely will be slower than an equivalent program written in C/C++. Same deal with Java.

Of course if you're writing "Hello World" the effect is much worse. If you're writing a huge program the requires reimplementing most of the library functionality of C# or Java, they will probably both run at the same speed.

The difference, however, is usually negligable for real life applications. Most processors spend the vast majority of their time on the NOP instruction anyway. smiley - smiley (NOP being the assembly langage instruction for No OPeration)

The tradeoff is usually speed of development. It's a lot faster to write a program when you can include a library instead of having to program the functionality yourself.


can someone help an absolute beginner in c++?

Post 20

MaW

Of course, asm can always be faster than even the best-compiled C or C++ (which will always beat C# or Java or anything else that's run as bytecode, like Perl 6 will be), but there's a point where you just cannot write everything in hand-optimised assembler anymore. Modern software is so insanely big and takes so long to write anyway, can you imagine hand-optimising something like Unreal Tournament 2003 written entirely in assembler? Sure, it's possible, but it'd reduce development time to the point where you'd probably never see any profit from the game, which would be silly.

So we accept a slight reduction in speed as a trade-off for having faster development time, more profits and programmers who still have some of their hair.

Gaming's one of the few areas where speed is absolutely critical anyway - other than real-time and embedded use, where resources are often rather limited. For your average piece of desktop software, say a web browser, sure you want it to be responsive and fast, but you don't need to drop into assembly to do that, because most desktop systems are massively overblown in terms of power anyway.

The only reason my system's really as fast as it is is because I play games on it - yes it's nice that doing image processing is pretty nippy, but for web browsing and so forth I could get away with something half as fast (or slower). So languages like C#, Java, Perl and so on become far more feasible - but they're not really games programming languages. They're desktop languages.

Perl 6, by the way, runs on a bytecode interpreter called Parrot that's seriously, seriously fast - it'll never beat native C or C++, but it should blow Java right out the water. Muahahahaha smiley - devil


Key: Complain about this post

Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."

Write an entry
Read more