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