This is about my 100s attempt to get started in programming, the previous 99 all ended the same way, I keep trying 2 or 3 days and I give up because I get nowhere, and I don´t understand why this should be so unbelievable complicated
As you can see, I haven´t totally given up yet, I always get back to it a week later or so, but you may still call me the bloodiest noob you´ve ever met, so forgive me for asking the dumbest questions
I´m not absolute new to programming, I know some basics in php/mysql
I´ve searched for online tutorials for beginners in C/C++, found some, and managed to write my first Hello World program to run in a DOS box
After that most beginner tutorials explain some basics about definig variables, get input, calculate and output, loops and stuff, that part isn´t new to me, a bit different syntax, but basicly the same as in php
After that, there comes the transformation of the Hello World program into a win32 application, sounds very easy, even the explanation looks very easy, but this is the point where I´m getting stuck
All the tutorials I found say something about the difference in code, like I have to use windows.h instead of iostream, but none of them mentions with a single word, that upon opening a new project and choose win32 application I get a main.cpp containing a whole bunch of code already where I have not the slightest clue WHERE to fit in the Hello World
Other tutorials I found are way too advanced for me, I don´t get a single word there
I keep searching, but I wonder, isn´t there an easy tutorial somewhere on the web which doesn´t explain what I already know and then either ends or jumps to a point where I don´t get a word?
I´d be willing to buy a book, but after this experience I almost expect it would be the same thing, either its about basics I know already or it begins at a point where I don´t understand anything at all
Can someone help me out? An easy tutorial for dummies, titled from web-programming to real programming or something like that?
I'm assuming you want to know how to code Win32 GUI programs right? I think this tutorial is the de facto standard for the Win32 API. :)
http://winprog.org/tutorial/
EDIT:
BTW here is the Win32 API Hello World program. :)
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(0, "Hello World!", "Note", MB_OK);
return 0;
}
Well a switch statement is like an if else-if. It is (I have been told) faster, and sometimes more efficient to use a switch.
Here is an example.
int main()
{
int a = 0;
if (a == 0)
//....
else if (a == 1)
//....
else if (a == 2)
//....
else if (a == 3)
//....
else
//....
return 0;
}
int main()
{
int a = 0;
switch (a)
{
case 1:
//....
break;
case 2:
//....
break;
case 3:
//....
break;
default:
//....
break;
}
return 0;
}
Do you follow that?
EDIT:
Sometimes the easiest way to do something isn't the easiest way to do something else. ;)
Like 10 * 3 = 30. Or 10 + 10 + 10 = 30. Ok not a good example, but I think you get the idea. :)
isn´t that what I´m doing? with the only difference that I have a concrete project to work on, rather than dry studying the theory?
Here I agree, for me too it's easier learning doing something that makes me happy when I see it does something useful, instead of coding only small samples. But... keep in mind 2 points :
1- without the theory (which you can learn while doing your test project) you'll not go too far.
2- your result has many, many and many chances to become something horrible and impossible to mantain. so, take it as-is, something to practice on and NOT something beautiful and bug-free. You'll notice it at the end when you'll think "why have I coded it like this ?" That happens to me when I'm in a hurry to see it working; when it's done, I start correcting again and again, up to I give up and rewrite from scratch.
and what about my actual question? how to "translate" code from other compilers? Theres not THAT much different between borland and gcc, I just think since this must be a pretty common problem for those who use prewitten libraries and classes to speed up their development, there should be an easier way than go through the code line by line
As I told you, Borland has some non-standard constructs that you simply can't translate to pure C++, at least for C++Builder 6 which I know.
For example, in C++Builder you can do such a thing :
class Test
{
private :
int anInteger;
void setInteger(int i) { if (i >= 0) anInteger = i ; }
public :
__property IntProp = {read = anInteger, write = setInteger} ;
};
Test test ;
test.IntProp = 2 ;
int j = test.IntProp ;
Even if I find it a beautiful construct (wondering why it's not included in Ansi C++....), that's NOT standard. In pure C++ you write :
class Test
{
private :
int anInteger;
public :
void setInteger(int i) { if (i >= 0) anInteger = i ; }
int getInteger(void) { return anInteger ; }
};
Test test ;
test.setInteger(2) ;
int j = test.getInteger() ;
As you see, even with this small code sample, you must change a lot. In C++ builder the __property construct is used widely, as are other non standard constructs. When you use the IDE to make an app skeleton, it gives you code full of such nonstandard constructs. Believe me, takes LOOOONG to convert to pure ansi C++.
Ciao
Max
Just to be precise: C is *NOT* a functional programming language. It's an imperative (or procedural, if you like this word more) language. Functional programming languages are languages like Haskell or Lisp.
Correct. C is sometimes mistakenly referred to as a functional language because the basic unit your imperative statements are organized into is called a function. Many people (including myself) fail to make the proper distinction.
Semantics regarding this usually do not come into play because there are hardly any functional languages in widespread use outside the academic world.
And as for the rest of your article... Well said!
Wow kagerato, great post. I learnt something from that. Thanks
I simply give my best -- there's no point in saying anything if you don't say something meaningful, I feel.
I got lost almost right away, mostly because there are no 2 tutorials for the same compiler, from videos at MSN how to write applications in visual C++ to plain C++ code I can use in CodeBlocks, they are not compatible, CodeBlocks allows me to import almost any format, but mixing them doesn´t work
Absolutely no clue what you're trying to say. "Formats"? Source code is normally stored as ASCII text (or occasionally, using an ANSI codepage or UTF-8 instead). As for C++ "dialects", read further.
I´ve noticed, most of them are written in VB or VC, I´ve even downloaded and installed Visual Studio Express, but for one the code is so way different from gcc, almost an entirely new language and the options are pretty much limited to what the compiler offers
The standard method of GUI programming using Visual C++ is MFC, the Microsoft Foundation Classes. As the name suggests, they are an object-oriented wrapper around the win32 API.
That doesn't have much, if anything, to do with the kind of code and samples you appear to be dealing with. I'm not sure where you picked up the idea that every compiler has its own C++ dialect, completely incompatible with another's. To a very limited degree, that was true ten years ago. It's not a matter of concern these days, as C++ has gradually become more and more standardized.
Visual Basic 6 is not in any way compatible with C or C++ code. It's an entirely different language, one that I would recommend newcomers stay away from.
Visual Basic .NET doesn't have nearly as many glaring problems as VB6. However, using it ties you to the .NET platform. (C# has alternate implementations and uses.) Since the changes made to Visual Basic for the purpose of transforming it into a .NET-compatible language have eliminated several of the original benefits of the language and platform, C# has seen much greater adoption.
By "Visual Studio Express", I believe you mean "Visual C++ Express". Upon last examination, the entire Visual Studio suite was not available for free as a single entity. Rather, there are separate packages for each language.
I don't recommend using Visual Studio -- it's huge and it provides little that a free IDE like CodeBlocks does not (assuming we're working with C++). Furthermore, the Express editions are, in essence, a marketing lure for the .NET platform and other Microsoft-dominated technologies.
Thats where I´m stuck now, I found just ONE tutorial that explains it short and easy at http://www.c-worker.ch/tuts/wstut_op.html (in german) but that one is written for borland and my attempts to translate it to gcc have failed so far, meaning I can´t even start implementing it into my project
Maybe someone here can help me out? How to mix code written for different compilers or how to translate it?
The source for both, is direct available on the page
Client: http://www.c-worker.ch/tuts/sock.c
Server: http://www.c-worker.ch/tuts/socksrv.c
This code is not "written for borland". It's win32 C, specifically using the winsock library. It will build using any C compiler, so long as 1.) the win32 headers are available and 2.) there are no syntax or linking errors.
I successfully compiled "sock.c" using gcc and this command:
gcc sock.c -o sock.exe -lws2_32
The linker command must go on the end there. (Took me a few minutes to remember this. Had it specified before the source file and was wondering why linker errors were appearing. The GCC man page warns you about this -- always a good idea to read the documentation.)
The fact that you have to explicitly link (using the -l switch, for GCC) to particular libraries is simply a part of C/C++ programming. This little winsock example fails just as spectacularly in Visual C++ if you fail to specify the library correctly.
This example is simple because it's a console application using winsock to provide basic networking facilities. Nevermind that it hardly does anything, let alone provide a "simple chatserver". Don't deceive yourself into thinking it's a simple matter to scale basic examples into production-quality complete applications.
Object oriented programming isn´t new to me (...)
So I know what it is about, I know specially in win32 applications theres a LOT of inherited stuff from the libraries
Oh? You don't seem to know what inheritance is. Inheritance does not mean "included from header files". Inheritance is basing a sub-class on the methods and fields of its parent. Using the win32 API does not involve inheritance. You missed the part about win32 being written in C, and hence lacking any object-orientation.
I still don't like the idea of global and local variables, but I do understand the concept (...)
In C, minimizing global variables is essential to preventing name conflicts and increasing the overall readability of the code. It's a core concept.
In C++, you don't use global variables, period. Furthermore, encapsulating classes effectively by minimizing the number of public fields and methods is a critical part of writing good code. Strong usage of encapsulation leads to easy isolation of bugs, among other benefits.
and what about my actual question? how to "translate" code from other compilers? Theres not THAT much different between borland and gcc (...)
Concerning the referenced code, there is no difference. No compiler-specific feature has been used. Indeed, it's rare to find an instance of it in C code to begin with.
Your problem is simple. Either you do not have your compiler installed correctly, or you do not know how to use it (or the IDE, whichever is relevant).