PDA

View Full Version : Need help! Starting with C++


Metalmurphy
July 12th, 2002, 10:06
Ok, i've been wanting to do this for a long time, and now that i'm on vacation I think I'm gonna start now. I'm thinking of starting to make my own plugins for ePSXe. The thing is that i haven't programed C++ before (wait!! don't start shouting and don't close the thread ;) )

I now it's hard to learn C++ but don't worry! I'm used to programming languages and I know the basics of programming (First time i did it I was 10, with Qbasic) And I have several bases of programing. I know Pascal, Qbasic, C, a litle of php, also mIRC scripting but that's almost nothing. etc...

Also I'm a quick learner and I understand this stuff well! All I need is for you to help me find good C++ tutorials, with this kind of plugin programming style, also some site's with released codes and stuff like that (i can learn much things when I see stuff that are already made and I now what they do).

Hope you can help me.

BTW, what are the major diferences between C and C++?

M.I.K.e7
July 12th, 2002, 10:12
C++ tutorials:
http://www.cprogramming.com/tutorial.html

Main differences between C and C++?
C++ is object-oriented and more complicated.

Metalmurphy
July 12th, 2002, 10:14
Yeah I know its more complicated :P What do you mean by object-oriented? Using shared files and stuff like that?

Thks for the tutorial

Ninjaa
July 12th, 2002, 10:22
C++ adds classes to the mix. Other than that, I don't believe there is much difference. (Although I am sure someone will correct me.)

M.I.K.e7
July 12th, 2002, 10:36
Object-oriented means that you have special functions called "methods", which are associated with classes. When you manipulate an object of such a class that normally works by refering to one of the methods.

Example:

Say we have a complex number and you have a function/method to increase such a number.

In C you'd have a struct which you pass as an argument to the function:
inc(complex_number);

In C++ you call the method of that specific object:
complex_number.inc();

Since the "operand" of the operation is already clear (it's the object) the method doesn't need a parameter.
If you take a look at the syntax it looks as if you were refering to a variable in a C struct, and C++ classes actually are derived from structs where you also define the methods in addition to the variables.

The whole thing looks a bit weird when you have operations with two operands:

C:
compare(cn1,cn2);

C++:
cn1.compare(cn2);

Take a look at some of the tutorials and try to get a book about it, because that topic is really a bit too large to be discussed here completely.

M.I.K.e7
July 12th, 2002, 10:40
Originally posted by Ninja
C++ adds classes to the mix. Other than that, I don't believe there is much difference. (Although I am sure someone will correct me.)

I'm not a C++ expert, but I think there is a little more difference, like operator overloading, templates, etc...
But the important thing are the classes and inheritance of course.

Metalmurphy
July 12th, 2002, 10:50
Mm... i think I getting the idea! Anyway! I'm already printing out the tutorials! Thks!

If any one know anything else please post! Like sorce codes of plugins for ePSXe! I already have some of project64 that might help but the more the better!

OmniDistortion
July 12th, 2002, 10:58
owie my head.... I need to learn some programming ....
I should shoot myself for admitting this but all I know is a small amount of HTML (to which I KNOW is small fry because its very familair to the human english language itself and is in actuality an advanced form of documentation) I tried learning VB but I guess I gave up?

Please could someone tell me what order I should learn everything in?... basically I wish to learn from an eazy programming language up to C++ (I dont care how long {well hopefully within 1/2 a decade maybe :p}... I may be smart but I seem to not be able to grip on something so...new as a programming language) thanks to all who can help me!

edit: typoz... this is another reason I would be a terrible programmer lol

Metalmurphy
July 12th, 2002, 11:14
OmniDistortion! Don't get me wrong but if you can't get a grip on any language and you give up easly i think you should try something else! If you just trying to program for fun then try something like 3D modeling or even Mapping like me!

But if you really want to learn how to program maybe you should start with something easy like Qbasic :P or Pascal just to get the basic!

I will be glad to help you if you need!

Ninjaa
July 12th, 2002, 11:28
Actually, C++ isn't that hard to learn. Just pick up a programming book and stick with it. Nothing beats a good textbook for teaching the stuff to you. The basics can be learned in a couple of days, and everything after that is just building on the knowledge.

OmniDistortion
July 12th, 2002, 11:38
MetalMurphy: I tend to give up only because I find more things of interest... (emulation alone is so addicting and takes up much of a person's life) 3D modling has taken a place in my heart as well as level design (I *attempted* level design for UT and DeusEX [both on UnrealScript] yet I have only succeeded in creating SC levels :cries: ) I really think that if I learned something more advanced it would help the emulation community a little more... and I was hoping to occupy in creation of something that isn't helped out in much such as sound CD-ROM plugins and the sort for starting out... sound good?

Ninja: I have... Murachs.. I need C++ for dummies or something to get me started then probably move onto Murachs... I'll probably need an E-book or something so everything will be on-screen lol! I don't like looking back and forth...

Yes I am 16 so I dont know if it has to do with a psychological mental developement or just my pathetic will power...

Edit: added last comments (forgot to add, silly me)

M.I.K.e7
July 12th, 2002, 12:09
@Metalmurphy:
BTW, why has it to be C++? I think most plugins are written in C, or am I wrong?
C++ has its advantages for big projects, but for smaller things C is not only sufficient but often better, because the binary is smaller and there is less overhead, which means more speed, and speed is an important factor in emulation.

@OmniDistortion:
I started programming when I was about 11 or 12 years old, so there is no real minimum age. But when you have problems trying to understand some of the concepts you should get a language that is good to understand, certainly not BASIC (I started with it as well, but it teaches you bad programming techniques) and probably not C (it allows too many tricks and has lots of pitfalls), more something like Pascal. When you understand the basics of one language it's much easier to learn another one.

Sometimes I wonder if there is a gift for programming or not, but I'm not sure...

OmniDistortion
July 12th, 2002, 12:14
I think I just might have that gift... I've gotten everywhere on ePSXe and 78% of anything just by reading up what I need to if I ever got stuck or (most the time) by messing around with everything until I get a reaction from the product (I really think this is due to negative/positive reasoning), and how many guests or random people do we see who come in here asking 1 bajillion million questions on how to "get a BIOS" eh? :lol:

edit: typos galore (this may be one reason why I shouldnt start programming :o )

ammoQ
July 12th, 2002, 19:51
Originally posted by M.I.K.e7
@Metalmurphy:
BTW, why has it to be C++? I think most plugins are written in C, or am I wrong?


Just wanted to ask the same question...

Badaro
July 12th, 2002, 20:53
Originally posted by Metalmurphy
Yeah I know its more complicated :P What do you mean by object-oriented? Using shared files and stuff like that?

Why nobody pointed to this thread yet? :)

http://www.ngemu.com/forums/showthread.php?s=&threadid=21555

[]s Badaro

Demigod
July 13th, 2002, 04:59
As M.I.K.e7 mentioned, the main difference between C and C++ is object-orientation. There are 3 key features to an object-oriented language and these are Data encapsulation, Inheritance, and Polymorphism.

C++ uses classes, which are kind of like a blue print or a prototype. You use the class to create what are known as objects. For example, you can make a class called "Human" and define certain functions such as walking(), talking(), and breathing() and data such as weight, height, and birthdate. You then use that class to create objects called Bob, Tom, and Shelley. These objects have the same basic functions defined in the class (walking, talking, breathing) but each holds their own data and differ slightly (e.g. Bob might be a bit taller than Tom). The data for the objects are not shared by the anything else and can only be manipulated by functions in the class. This is known as Data Encapsulation, keeping the object data seperate from the rest of the program. This makes managing data easier, especially for really big programs.

You can also define a new class based on an existing class. For example, let's say we make a new class called "Spiderman" and we base it on the "Human" class. The new class will have all the features of the base class but will also have its own functions as well. So let's say we make an object called Peter_Parker from the "Spiderman" class (based on "Human" class). Peter_Parker has all the functions of the "Human" class (walking, talking, breathing) but also has its own special functions (wall_crawl(), web_shoot(), spider_sense() ). We can say that the "Spiderman" class is inherited from the "Human" class. This is known as Inheritance, inheriting features from another class to make a new class.

We can also define a function to do different things. For example, let's say John is a graphics artist and his boss tells him to draw a circle. He uses a pencil and draws a circle. Then his boss tells him to draw a rectangle. He takes the same pencil and uses the same techniques (drag the pencil over the canvas) but draws a rectangle this time. Then the boss tells him to draw a triangle and he does the same. With C++ you can do a similar thing. You can call a general function (e.g. Draw() )which can work with other specialized functions to do different things. This is called Polymorphism, using one function to do many different things.

I hope this is helpful to get a grasp of some of the concepts of object-oriented languages. There are lots of other capabilities of C++ (such as inline functions, operator overload, etc.) but the above 3 concepts are the key features of OOP.

Demigod
July 13th, 2002, 05:06
Originally posted by M.I.K.e7
@Metalmurphy:
BTW, why has it to be C++? I think most plugins are written in C, or am I wrong?I think epsxe itself is written in C. You don't really need to know C++ for small programs. It's only useful for really big projects (e.g. Windows 2000).

mikeshoup
July 13th, 2002, 06:32
Originally posted by Demigod79
I think epsxe itself is written in C. You don't really need to know C++ for small programs. It's only useful for really big projects (e.g. Windows 2000). Uh... I have to disagree with you on that. C++ is object oriented and used when speed is still a factor, but doesn't need to be a big issue. Every C++ compiler adds extra overhead to all of the functions which slow things down. Most emulators and plugins are written in C to avoid the overhead. Alot of windows 2000 is written in C, alot is in C++, and a whole lot is ASM. The choice between C and C++ really depends on what you are programming, and what the objective is.

As for my personal choice, I tend to do a C/C++ mix. In mJoy, the joystick reading functions are written in a C++ module (with C LINKAGE for compatibility), and the main pad functions are written in a C module. I only use C++ when I feel it would make it easier to program.

Besides, C still has some object oriented properties. Take structs for example. A variable of type struct could be considered an object. Still though, in order to be object oriented a language must have polymorphism of which C does not.

ammoQ
July 13th, 2002, 07:05
polymorphism in C? itīs called the void pointer.

Demigod
July 13th, 2002, 19:47
Originally posted by mike9010
Uh... I have to disagree with you on that. C++ is object oriented and used when speed is still a factor, but doesn't need to be a big issue. Every C++ compiler adds extra overhead to all of the functions which slow things down. Most emulators and plugins are written in C to avoid the overhead. Alot of windows 2000 is written in C, alot is in C++, and a whole lot is ASM. The choice between C and C++ really depends on what you are programming, and what the objective is.
I'm saying that OOP doesn't make sense for small programs. You can just do it in C and it'd be more simple and efficient. When you have very large programs there are a lot of data to manage and it gets difficult with structured programming. C++ is also easier when developing programs in teams, since the code is independent of the main code (just work on your own part, no data overlap).

Metalmurphy
July 15th, 2002, 09:51
Thks a lot for the info dudes! I thought that it would have to be in C++, but if C works fine that cool for me! Thks a lot!

KillerShots
July 26th, 2002, 19:46
Originally posted by M.I.K.e7


In C++ you call the method of that specific object:
complex_number.inc();



I'd just use the "operator++()" function and it would come out as:

complex_number++;

Originally posted by M.I.K.e7


C:
compare(cn1,cn2);

C++:
cn1.compare(cn2);



or...use "object operator|(object x)"
so you end up with cn1 | cn2;

...Then again, I expect I would also be corrected. That's what I find so interesting here, there's just so many ways to do the same thing. The above way just lets me visualize things a lot easier, but it does the same thing :) :fart: :)

DragonSoull
July 26th, 2002, 21:08
http://www.BruceEckel.com

"Thinking in C++"
It's the best C++l book i hever found (trying to learn two :)) and it's free :P

AtomicFeline
July 26th, 2002, 22:11
Originally posted by Metalmurphy
Also I'm a quick learner and I understand this stuff well! All I need is for you to help me find good C++ tutorials...


Learning your first programming language takes time and patience. Learning a second one is considerably easier. I took Visual Basic two years ago and last summer I taught myself C++ in two months. To be honest, the book that taught me it all was C++ For Dummies. When I took the course the following year, I knew more than the teacher. Two months......

paulsy
July 31st, 2002, 04:44
i am using the tutorials at http://www.axion-network.net/tutorials.php

also trying to learn c++


dragonsoull wich book r u using from the website u posted

OmniDistortion
August 2nd, 2002, 03:51
hey guys its been about a month but I just picked up "C for dummies" and I am gonna start with that...

BTW I dont hear much about ASM but I noticed that its especially used for emulation...why is that? And why only that?

Zero MH
August 2nd, 2002, 03:52
Is ASM short for assembly? If it is then assembly is used to speed up emulation since it is faster than C++.

OmniDistortion
August 2nd, 2002, 03:55
so it's just for speed? easier compilation?

M.I.K.e7
August 2nd, 2002, 15:16
Originally posted by OmniDistortion
{assembly}
so it's just for speed? easier compilation?

Assembly isn't compiled, it's run through an assembler.

Assembly isn't a high-level language like C or Pascal, but a human-readable for of the machine language that the processor understands, and which is also the end result of a compiler run.

Assembly uses so-called mnemonics (short names) to make the instructions readable, otherwise machine language would be just a bunch of numbers.

Here is an example of a short assembly sequence with the corresponding machine code following behind the semicolon:

mov eax, [esp+4] ; $8B442404
inc eax ; $40
ret ; $C3


What this code does is to take a value from the stack (actually a function acrgument), copy it into the register EAX, where it is increased, and the routine returns that result because EAX is the result register by convention.
So basically it's just a simply function that adds 1 to a value you hand it, but it serves well as an example in that case.

The reason why it is often used in emulation is that you have to deal with processor emulation, and one of the fastest ways is to transform the original operations into instructions your current processor understands.

The most extreme way of doing this is to actually translate the old code into code for your current processor, a technique I did a few postings about:
http://www.ngemu.com/forums/showthread.php?s=&threadid=20491

I guess I caused more disturbance then help now...

ZeRo[PmD]
August 3rd, 2002, 01:06
it's very hard c++

jegHegy
August 3rd, 2002, 02:27
also, really experienced linux programmers say c is much better than c++ (faster, as they say), and they proved it too! (http://www.mplayerhq.hu, they left avifile with speed far behind, and avifile was written in c++)

nyaaa

OmniDistortion
August 3rd, 2002, 09:19
I read all about Assembly...

Basically its like this: A scale (I included popular microsoft programming languages along with ASM)
Binary(hard)<------ASM------C++----C#------C----VB----->(easy)English

The closer you are to binary the more abilities ye shall obtain as well
More speed as well as reliability take the cake as well (all in a neat package)
Problem is, well, the closer you are to machine language or binary the longer and more frustrating programming can be and that is why proggrammers choose to do others (simply for ease and to not lose their minds over stress)

See? Omni can learn basic programming knowledge and teach it to others! (trust me murphy I am NOT going below C [I found out its easy enough just have to understand very few things and the rest is reference...])

edit: I just installed those 30.2 nvidia drivers so my res. was 640X480 while typing this lol! (it's pissing the bloody hell oughtta me!)

ammoQ
August 3rd, 2002, 09:39
I think you misplaced C. It's actually faster than anything but assembler; and althought it might be a bit easier to learn than C++, Java or C#, it can be difficult to make programs that are well suited for object-oriented programing, something that hardly exists in C.

OmniDistortion
August 3rd, 2002, 09:43
:doh: I just realised how correct you are - some things can be variable making my scale absoslutly incorrect in some ways (mostly on how fast each one is) oh yeah and I would like to mention VB now has OOP which I find very odd (VB.net that is....I dont know what the .net series is though... can someone enlighten me?)

M.I.K.e7
August 5th, 2002, 07:53
Originally posted by OmniDistortion
oh yeah and I would like to mention VB now has OOP which I find very odd (VB.net that is....I dont know what the .net series is though... can someone enlighten me?)

.NET is Microsofts strategy to kill off Java and take over even more parts of the internet.
Part of the .NET package is a machine independent code (similar to the bytecode for a JVM), which all .NET compilers produce, which at the moment are C#, VC++, and VB.

Interestingly enough, Microsoft actually put up C# and the CLI (Common Language Infrastructure) for standardization (http://www.ecma.ch/ecma1/STAND/ecma-334.htm and http://www.ecma.ch/ecma1/STAND/ecma-335.htm), which Sun failed to do with Java/JVM twice.

OmniDistortion
August 5th, 2002, 07:58
1: how did they standardize it?
2: interesting fact: Java was going to be named oak but the dude who created woulda had some trouble with oak soft or something
:D I dont know why I even bothered adding that in... (I guess I just like adding random facts in)

M.I.K.e7
August 5th, 2002, 08:41
1: how did they standardize it?

What do you mean by "how"?
If they have an open documentation at ECMA they should stick to it. Let's see if they do...
But it's quite funny that they have open documentation for it, because they certainly don't do that for every stuff.

Sun on the other hand don't seem to want to loose control over Java, which is most likely the reason why tried to make it ISO twice but didn't pull it through.

2: interesting fact: Java was going to be named oak but the dude who created woulda had some trouble with oak soft or something

Rumour has it that James Gosling has an oak tree in front of his window at work...
But at the time it was still called Oak it was intened for an interactive TV device, and certainly wasn't thought for the internet or portability.
After that interactive TV project was dropped they pushed for the internet to do at least something with the language they created, so the JVM was added rather late, which shows in its bad design.

OmniDistortion
August 5th, 2002, 09:29
Originally posted by M.I.K.e7
interesting fact: Java was going to be named oak but the dude who created woulda had some trouble with oak soft or something

Rumour has it that James Gosling has an oak tree in front of his window at work...
But at the time it was still called Oak it was intened for an interactive TV device, and certainly wasn't thought for the internet or portability.
After that interactive TV project was dropped they pushed for the internet to do at least something with the language they created, so the JVM was added rather late, which shows in its bad design. [/B]

Yes I knew about the oak tree outside his window...
I believe the language was made to make two devices comminicate to each other (I dont think it was a TV I think it was some new project they were making... some device that they were creating) james found C frustrating to use while programming for this project so he spent many a night working on his own programming language and thats how Java was devoloped..

Ninjaa
August 5th, 2002, 13:44
I just have a quick question to add to this debate over whether C or C++ is better. I don't think there is any question that C is faster than C++, and the languages are very similar. But here's the problem.

I have never taken a course in C, or read any books on it. I was taught C++ in my first year of University, and I have been teaching myself more advanced things over the summer. How hard would it be for me to downgrade my thinking so that I can program things in C? (Assuming that I became proficient in C++ first)

OmniDistortion
August 5th, 2002, 13:46
aww its not as hard (I wouldnt call it downgrading your thoughts)
I dont believe it has Object-oriented programming or anything so you would pick it up in no time!

M.I.K.e7
August 5th, 2002, 14:12
Originally posted by Ninja
I have never taken a course in C, or read any books on it. I was taught C++ in my first year of University, and I have been teaching myself more advanced things over the summer. How hard would it be for me to downgrade my thinking so that I can program things in C? (Assuming that I became proficient in C++ first)

Not too problematic I guess (unless you are really in need of the STL all the time, because you won't have it in ANSI C).

You only have to be clear that you don't have classes, inheritence, and all that.
Instead of methods in classes you have global functions. What data you used to pack in classes you can pack in structures instead and still access it with the same syntax.

After all C++ contains C, so it also depends on how much OOP-centric you programmed C++. When you never had global functions (apart from main() that is) and always had lots and lots of inheritance (ie. your C++ programs look a bit like Java) then you'll have a harder time, but otherwise it shouldn't be too complicated.

One thing you have to get used to is that there is no "new" and "destroy", you'll have to use "malloc()" and "free()" and have to be very careful to allocate the right amount of memory or you will get segmentation faults.

OmniDistortion
August 5th, 2002, 14:16
M.I.K.e7: one question: do you develop anything, such as create any plugins or code any emulators?

M.I.K.e7
August 5th, 2002, 14:29
At the moment I don't do private development (only research in dynamic recompilation as shown in anyother thread which I think I have mentioned here before), and at work I'm currently doing reading into yet another development environment (PowerBuilder this times), so I'm not doing that much practical work there either at the moment.

I know too less about graphics and sound programming to do a complete emulator or a plugin (especially since I don't do any private Windows development), but I'll continue my research, and maybe I can pack some stuff in a longish article to demystify dynamic recompilation for developers who seek a way to speed up their CPU emulation.

OmniDistortion
August 5th, 2002, 14:32
ah so thats why you arent devoloping anything...
well... I program..um...some html...and tiny bit of C and Java so I am way up there with you M.I.K.e7!
("whatever omni")

Ninjaa
August 5th, 2002, 14:37
Yeah, that's about what I thought Mike. Thanks for the reply. I think I will just stick with C++ until there comes a time that I really need some performance tweaks.

ammoQ
August 5th, 2002, 14:38
Downgrading from C++ to C can be hard when you are used to use some constructs in C++ and donīt have them in C, so you have to figure out how it can be done in C. I would not underestimate the time necessary to find your way into C.

M.I.K.e7
August 5th, 2002, 15:47
Originally posted by OmniDistortion
ah so thats why you arent devoloping anything...

The reasons are
at work: I simply don't have a project to work on yet
at home: I'm so damn lazy... :(

well... I program..um...some html...

I don't normally count that as programming, otherwise I programmed LaTeX as well....
But if you want to count that:
http://www.dynarec.com/
http://www.be-faq.de/
http://www.linguistik.uni-erlangen.de/~mlkoenig/SElliott.html
Nothing exceptional, I just want to provide information...

and tiny bit of C and Java so I am way up there with you M.I.K.e7!

Well, I programmed in BASIC (ST-Basic, OmikronBasic, BBC BASIC, VBS), TurboPascal, C, Modula-2, Assembly (68K, ARM, MIPS, x86), Scheme, Miranda, Prolog, Clarion, PL/SQL, and probably some other langauges I forgot, so learning new languages is to me more like trying not to mix up all the languages I know...

ammoQ
August 6th, 2002, 01:51
It's a shame that you are so lazy, M.I.K.e7! Someone with your skills should do something good for mankind, like writing a better GUI for Linux! ;)

M.I.K.e7
August 6th, 2002, 07:35
Originally posted by ammoQ
It's a shame that you are so lazy, M.I.K.e7!

Tell me about it...
But after a 40 hour week and not having holidays for about 15 months (that happens when you are fired before you can take holidays and have to start at a new firm) I'm not really in the mood of doing anything when I come home. But at the moment my 7 year old niece is here for a visit, so the time per day I might have for myself basically shrinks down to about 2 hours per day...

Maybe I think of doing something productive after I had a few weeks off...

Someone with your skills should do something good for mankind,

Hey, but I'm a master of evil ;)

like writing a better GUI for Linux! ;)

Of no... Then I could start writing a decent kernel as well...

DoubleD_99
August 17th, 2002, 23:12
Do C over C++ believe me! I first started in C++ and soon found out that the only real good part of C++ is that it is more organised for bigger program use. Everything else that you can think of usually is better in C. Like most of the development kits to make video games for GB, N64, or PSX is in C only and C is faster for making programs like emulators, games, plugins for ePSXe (Above example) and more. Also C++ has more of a header (usually) so the programs are bigger is size. There are a lot more examples, but for now i rate C:thumbup:

Ninjaa
August 26th, 2002, 20:11
To program for windows you need some C++ experience though, right? Isn't the Windows SDK based around classes?

ammoQ
August 27th, 2002, 00:02
Ninja, AFAIK the Windows API is basically a C-API; you get the classes from the MFC.

Ninjaa
August 27th, 2002, 12:21
Ok, I guess I misunderstood.

chillypacman
September 5th, 2002, 08:26
Originally posted by Demigod79
I think epsxe itself is written in C. You don't really need to know C++ for small programs. It's only useful for really big projects (e.g. Windows 2000).

I dont think they used c for programming win 2000 or any of the other windows most likely was some big time programming language which no one except microsoft knows of

OmniDistortion
September 5th, 2002, 08:29
I am pretty sure they would have used either C++ or ASM... (they cant make much a market out of a programming language that is easier to even make OSs easier... they would use it for marketing as well.... either that or we would have at least heard of it)

ammoQ
September 5th, 2002, 09:59
I'm pretty sure nearly all of windows is written in C, Assembler and C++. Some small parts of the new .net-Server are written in C#. What's the point in using a big time programming language nobody knows of? They also have the need to hire programmers that work for them or to contract other companies to deliver parts for the whole Windows-Package. Doesn't make sense to use a language nobody knows.