Hi Al,
The code is written in source boost C, and the X++ means increment X, a bit like X = X + 1 in Basic.
It's just C/C++ has the ++ operator to increment the variable instead of having to do it like in Basic, it also has the -- and some others like += -= which would for example:
Code:
X = 1;
X++; //X = 2
X+=4; 2(Original X after ++) + 4 = 6
So X Plus Equals 4. It really is simple once you get into it.
The main differences between Basic and C is the use of the terminator ( ; ) you have to put a semicolon after each line to tell it that is the end of the command.
The curly braces {} which tells the compiler that this is the function for a particular statement, such as an IF statement
In basic you would do:
Code:
if a = b then
a = a + 1
end if
in C/C++ you would do this:
'=' in C means assign, == means compare, != means not equals. Because the code for the if statement is inside curly braces you dont need an "end if" statement, the '}' is effectively the "end if" and the a++; is already covered, you will also notice the if clause is in ( ) brackets, this is another small change.
The last real one is the way C/C++ implements the varibles, there is no DIM keyword, and they are case sensitive.
For example,
Code:
In Basic:
DIM I as Integer
DIM A as String
i = 1
a = "Test"
The above example all would be happy
In C/C++:
int i;
string a;
I = 1;
a = "1234";
Now, in the above example, 'I' would be invalid, instead we have to use:
i = 1;
My examples are not perfect, but they will hopefully allow you to understand how to either:
a) move to C/C++ OR
b) convert code from C/C++ into BASIC.
Functions are also done in the same fashion, with curly braces to indicate the start and end of a function and a declaration.
You will sometimes notice what is called a "Function Prototype" which in simple terms tells the compiler what is there before you implement the function.
For example ( note VOID in C/C++ means it has nothing to return):
Code:
void PrintStr(string str); //Notice the ; ? This means it is allocating that function and that it will be created somewhere later on in the program.
int main() //Entry point
{
//Blah blah do something
PrintStr("Hello World"); //See, we have used the function BEFORE it has been created, but it has been allocated.
return 0; //Return 0 (exit code as in main function)
}
void PrintStr(string str)
{
printf("%s\r\n", str);
}
Now without going into details of C functions etc, hopefully this will help you to work out what is going on. If you attempted to call the function without actually declaring it properly you would get a compile error.
Regards
Wilksey