Comparison of C/C++ and FreeBASIC
C/C++ |
variable declaration
int a; int a, b, c; |
dim as integer a, b, c
uninitialized variable
int a; |
zero-initialized variable
int a = 0; |
initialized variable
int a = 123; |
array
int a[4]; a[0] = 1; |
a(0) = 1
pointer
int a; int *p; p = &a; *p = 123; |
dim p as integer ptr
p = @a
*p = 123
structure, user-defined type
struct UDT { int myfield; } |
myfield as integer
end typetypedef, type alias
typedef int myint; |
struct pointer
struct UDT x; struct UDT *p; p = &x; p->myfield = 123; |
dim p as UDT ptr
p = @x
p->myfield = 123
function declaration
int foo( void ); |
function body
int foo( void ) { return 123; } |
return 123
end functionsub declaration
void foo( void ); |
sub body
void foo( void ) { } |
end sub
byval parameters
void foo( int param ); foo( a ); |
foo( a );
byref parameters
void foo( int *param ); foo( &a; ); void foo( int& param ); foo( a ); |
foo( a )
statement separator
; |
end-of-line
for loop
for (int i = 0; i < 10; i++) { ... } |
...
nextwhile loop
while (condition) { ... } |
...
wenddo-while loop
do { ... } while (condition); |
...
loop while conditionif block
if (condition) { ... } else if (condition) {... } else {... } |
...
elseif condition then...
else...
end ifswitch, select
switch (a) { case 1: ... case 2:break; case 3: ... default:break; ... }break; |
case 1
...
case 2, 3...
case else...
end selectstring literals, zstrings
char *s = "Hello!"; char s[] = "Hello!"; |
dim s as zstring * 6+1 = "Hello!"
hello world
#include <stdio.h> int main() { printf("Hello!\n"); }return 0; |
comments
// foo /* foo */ |
/' foo '/
compile-time checks
#if a #elif b #else #endif |
#elseif b
#else
#endif
compile-time target system checks
#ifdef _WIN32 |
module/header file names
foo.c, foo.h |
typical compiler command to create an executable
gcc foo.c -o foo |