# I'm learning C++ anyone got any tips?



## Nick89 (Oct 22, 2010)

Tips, online tutorials, anything really.


----------



## Kreij (Oct 22, 2010)

Links : The Official TPU Programming links thread

Tip : When tempted to fight fire with fire, remember that the Fire Department usually uses water.


----------



## char[] rager (Oct 22, 2010)

When I was learning C++ at my school, we used this book.

Another tip:  actually type out, compile, and run EVERYTHING that you do not understand by simply reading it. It is proven that writing something down is almost 100% guaranteed to be in your memory longer than if you learned it simply by hearing it.


----------



## MxPhenom 216 (Oct 23, 2010)

screw C++ go with XNA and CSharp


I did C++ for a semester at school and hated it. honestly


----------



## JD15 (Oct 23, 2010)

Some good info here.

http://msdn.microsoft.com/en-us/beginner/cc305129.aspx


----------



## streetfighter 2 (Oct 23, 2010)

nvidiaintelftw said:


> screw C++ go with XNA and CSharp
> 
> 
> I did C++ for a semester at school and hated it. honestly



That seems like such an odd thing to say but I guess it's logical.  

I've been using C/C++ for years and it's still my favorite language for no-BS, fast as hell, low memory applications.  So far I've found it fairly trivial to port (most of) my C/C++ programs from Windows to Unix/Linux (or vice versa) because there are many similar APIs.  I use the 32-bit and 64-bit Windows versions of mingw because MS VC++ makes it rather harder to port programs (and also because mingw is open source!!).

Obviously Java is my language of choice when portability is my greatest concern (but it rarely is).  Python is my go to language for getting shit done and, as a bonus, it's pretty darn portable.  I use C# when I need an interface made quickly in Windows and having the code be "managed" is quite nice.  I've always been wary of the .NET framework because of the perceived lack of portability.  I hear that the .NET runtime environment called Mono makes portability a moot point.  I've coded in C++/CLI but the menagerie of string types confused the ever living shit out of me and resulted in some really awkward (and inefficient) type conversions.

One of the benefits of learning C/C++, which is not to be understated, is that it will help a lot if you ever want to program microcontrollers (ie. build robots, etc.) or embedded devices (ie. make sensor networks, etc.).  Most specialized hardware has a limited supply of compilers and of those most only compile C and C variants.  Another advantage is that C/C++ gives you much tighter control over how the hardware is utilized so you are forced to learn about computer architecture in order to optimize your code.

Knowing is half the battle. GI JOEEEE!


----------



## CDdude55 (Oct 26, 2010)

I'd also like to get started into programming, as i really like learning more then my current computer knowledge which is mostly hardware. I think it would be good to expand my horizon.

Good info guys!


----------



## Yukikaze (Oct 26, 2010)

nvidiaintelftw said:


> screw C++ go with XNA and CSharp
> 
> 
> I did C++ for a semester at school and hated it. honestly



However, the fact that you hated it doesn't make it bad or useless. Just not your cup of tea.

The programming I enjoy most is C/C++ coding, followed by Python, then Java. I do all three every week (C/C++ at work, the rest at the university).


----------



## Solaris17 (Oct 26, 2010)

Kreij said:


> Links : The Official TPU Programming links thread
> 
> Tip : When tempted to fight fire with fire, remember that the Fire Department usually uses water.



unless you forget to pay your taxes.


----------



## Kreij (Oct 26, 2010)

If someone decides to learn C# as their first programming language, my suggestion would be to jump into WPF/XAML from the beginning.

If you have visions of a game programming career, C++ is the one you want at the moment (although there is much to be said about the content pipeline in XNA).

If you are Dutch and are working toward becoming a TPU supermod, then VB is the way to go.

If you want to impress your friends in the scientific community while at the same time learning something rather obtuse and esoteric, learn F#.

If you want to be a really stud, ninja programmer ... learn every programming language available .. and to prove your worth, start with COBOL and Pascal.

Just some tips from Old Uncle Kreij


----------



## Crushed Ice (Oct 26, 2010)

Whether you're going with C++ or C#, you need to own Charles Petzold's books. 
Programming Windows, Fifth Edition 
Programming in the Key of C#

Yes, Petzold's Windows book is over ten years old, but the C++ standard hasn't really changed since then, nor has much of the Windows API.
Petzold's books are completely comprehensive, and a perfect reference. Any time I've thought "I'd like to do X" X has been in that 1,500 page monster. It's well indexed too.


----------



## CDdude55 (Oct 27, 2010)

This is probably pretty crappy and easy to you guys, but this is really my first shot:

I just used some random sentences about cookies and stuff lol:







It compiled and ran.


----------



## streetfighter 2 (Oct 27, 2010)

CDdude55 said:


> This is probably pretty crappy and easy to you guys, but this is really my first shot:
> 
> I just used some random sentences about cookies and stuff lol:
> 
> ...



Great now make one float variable and use a bitmask to store all 3 variables.

JUST KIDDING. 

What program/compiler are you using for writing code?
Also, I don't think this was mentioned but this is where I go when I forget something, as I quite routinely do.  I don't know how useful it is for a beginners but it certainly helps me debug sometimes.


----------



## PVTCaboose1337 (Oct 27, 2010)

And the batting average came out wrong amirite?  Think it should be %f cause it is a float, instead of %d which refers to an int.  

So:

printf("blah blah batting avg is %f", battingaverage);


----------



## Nick89 (Oct 27, 2010)

Just so you guys know, I'm going to have to also learn C# I believe.

This whole thing started because I want to make a game for the Iphone, YEA I know "Iphone game luls" 

But this is one of the easiest platforms to make games for.

If anyone has any information about this also, it would be appreciated.


----------



## Kreij (Oct 27, 2010)

@CDdude : Great start !! Now write a program that picks winning lottery numbers so we can get some money to start our own game studio.  

@Nick89 : Ask any questions you have on C#. Links and availability of C# tuts and reference docs is the same as for C++ (ie. they are all over, and there are many great books). If you want to starty a thread specific to C# questions that you may have, that's fine too.


----------



## CDdude55 (Oct 27, 2010)

streetfighter 2 said:


> Great now make one float variable and use a bitmask to store all 3 variables.
> 
> JUST KIDDING.
> 
> ...



I did everything in Dev-C++ http://www.bloodshed.net/



PVTCaboose1337 said:


> And the batting average came out wrong amirite?  Think it should be %f cause it is a float, instead of %d which refers to an int.
> 
> So:
> 
> printf("blah blah batting avg is %f", battingaverage);



Ahh,thanks for pointing that out!



			
				Kreji said:
			
		

> Great start !! Now write a program that picks winning lottery numbers so we can get some money to start our own game studio.


----------



## char[] rager (Oct 27, 2010)

If I was programming for Windows, in general, would the Win32 API be the best choice in terms of fastest execution performance?


----------



## ctrain (Oct 28, 2010)

CDdude55 said:


> I did everything in Dev-C++ http://www.bloodshed.net/



Don't use dev C++, it's had no support for a loooong time, it's hideously out of date and broken by modern standards. go get visual studio, it's free and is basically the pinnacle of IDE's.



char[] rager said:


> If I was programming for Windows, in general, would the Win32 API be the best choice in terms of fastest execution performance?



You can trust it to be fast, yes.


----------



## streetfighter 2 (Oct 28, 2010)

ctrain said:


> Don't use dev C++, it's had no support for a loooong time, it's hideously out of date and broken by modern standards. go get visual studio, it's free and is basically the pinnacle of IDE's.



wxDev-C++ (a wxWidgets extension of Dev-C++) is somewhat more recent and is a great IDE for making basic dialog applications.

VS Express is free, as you correctly mentioned, but it can be a bit annoying to work with compared to the pay versions IMO.  (I just realized that's an old version that I linked.  You can get VS 2010 Express from Microsuck.)

Honestly my favorite IDE is Eclipse.  But I'm mega old sk00l and do all my programming in Notepad++ and compile with Mingw using batch files.


----------



## Kreij (Oct 28, 2010)

char[] rager said:


> If I was programming for Windows, in general, would the Win32 API be the best choice in terms of fastest execution performance?



The phrase "programming in general" is a bit nebulous, but overall the Win32 API are fast and the latest MS compilers do a fine job of optimization.

However, the other half of the equation is time spent on application development.
C#, as a RAD language, uses a lot of wrappers around the Win32 APIs to make programming a lot less tedious and "safe".
Visual Studio, _in my opinion_, is the finest IDE available today.

WPF has added a lot of new APIs to the equation and has extended the ability to customize the UI an incredible amount, and if you use XAML you can program in a completely declaritive language and the UI look and feel is totally segregated from its underlying functionality.

Just my personal observations. Quit reading TPU and get back to coding.


----------



## char[] rager (Oct 28, 2010)

Well, we are going to start learning C# next semester, but I have already started teaching myself the language. I have to agree with you Kreij, C# is an excellent language for RAD, and in my opinion, for what I do, it is much better than C++.

However, if I did decide to take classes in Win32 development (not required for my major,) I would have to go back to C and C++. I admit from reading several online tutorials, the Win32 API will drive me 

As far as IDEs are concerned, I *LOVE* VS2010 Ultimate. It is the best IDE I have ever used and I have used some others.


----------



## Kreij (Oct 28, 2010)

You do not have to use C or C++ to access the Win32 APIs. 
You can do it from C# or VB if so needed.

Just about everything you will need for Win32 calls can be found at pinvoke.net


----------



## char[] rager (Oct 28, 2010)

Thank you for the information 

I did not realize just how large it was


----------



## CDdude55 (Oct 28, 2010)

Is it true that you can't make multi-threaded software with the C language?


----------



## char[] rager (Oct 28, 2010)

If you google parallel programming in C or C++, you will find some stuff.

In C#, one can learn the *parallel.for()* syntax.


----------



## streetfighter 2 (Oct 29, 2010)

CDdude55 said:


> Is it true that you can't make multi-threaded software with the C language?



There are actually several methods of making threads in C which depend on your platform.  For unix/linux I use pthreads.  In Windows with C you can use the "process.h" header which is part of the C run-time (CRT) with the _beginThread API. (example).  With C++ there are a bunch of other ways depending on your style and what you're looking for.

Lots of info: http://msdn.microsoft.com/en-us/library/172d2hhw.aspx

It should be noted that in Unix you can create threads by forking.  Win32 does not support forking (so far as I know).

In C# I use "using System.Threading;" and creating a thread is as easy as "Thread t = new Thread(new ThreadStart(myFunc));" where myFunc is a function.


----------



## Kreij (Oct 29, 2010)

Information on Processes, threads and apartments for inquiring minds.

C# makes multi-threading pretty painless, but you still need to be aware of what you are doing to avoid the usual pitfalls (timing problems, deadlocks, etc.)

Note that if you are writing a STA app, the underlying framework still runs UI stuff in seperate threads so as not to make the app unresponsive. This can cause you moments of painful hair ripping if you are trying to communicate with a UI element that is in its own thread and you are not aware of that fact. Google "Rogaine" if hair loss gets excessive.


----------

