### Comparison of C/C++ and FreeBASIC

C/C++
FreeBASIC

variable declaration
int a;
int a, b, c;
dim a as long
dim as long a, b, c

uninitialized variable
int a;
dim a as long = any

zero-initialized variable
int a = 0;
dim a as long

initialized variable
int a = 123;
dim a as long = 123

array
int a;
a = 1;
dim a(0 to 3) as long
a(0) = 1

pointer
int a;
int *p;
p = &a;
*p = 123;
dim a as long
dim p as long ptr
p = @a
*p = 123

structure, user-defined type
struct UDT {
int myfield;
}
type UDT
myfield as long
end type

typedef, type alias
typedef int myint;
type myint as long

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
int foo( void );
declare function foo( ) as long

function body
int foo( void ) {
return 123;
}
function foo( ) as long
return 123
end function

sub declaration
void foo( void );
declare sub foo( )

sub body
void foo( void ) {
}
sub foo( )
end sub

byval parameters
void foo( int param );
foo( a );
declare sub foo( byval param as long )
foo( a )

byval pointers to parameters
void foo( int *param );
foo( &a );
declare sub foo( byval param as long ptr )
foo( @a )

byref parameters
void foo( int& param );
foo( a );
declare sub foo( byref param as long )
foo( a )

statement separator
;

:
<end-of-line>

for loop
for (int i = 0; i < 10; i++) {
...
}
for i as long = 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!"

// foo
/* foo */
' foo
/' foo '/

compile-time checks
#if a
#elif b
#else
#endif
#if a
#elseif b
#else
#endif

compile-time target system checks
#ifdef _WIN32
#ifdef __FB_WIN32__

foo.c, foo.h
foo.bas, foo.bi

typical compiler command to create an executable
gcc foo.c -o foo
fbc foo.bas
{"ft_lang_label":"__label__en","ft_lang_prob":0.61207134,"math_prob":0.97900575,"size":2955,"snap":"2022-05-2022-21","text_gpt3_token_len":1012,"char_repetition_ratio":0.13690275,"word_repetition_ratio":0.18302828,"special_character_ratio":0.37055838,"punctuation_ratio":0.21212122,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95664275,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-17T01:28:07Z\",\"WARC-Record-ID\":\"<urn:uuid:fa6933d0-1f83-4b97-aeaf-2406c598f935>\",\"Content-Length\":\"12156\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:060ef9be-643b-41e7-a6d3-43197b5c22e7>\",\"WARC-Concurrent-To\":\"<urn:uuid:3bdad59e-b3eb-4eca-8e77-1fdc215311ec>\",\"WARC-IP-Address\":\"198.252.100.173\",\"WARC-Target-URI\":\"https://www.freebasic.net/wiki/TblComparisonC\",\"WARC-Payload-Digest\":\"sha1:JR7FKHPYEULWDITDPPCC2MSM6K2R4TKE\",\"WARC-Block-Digest\":\"sha1:JXNB2ES36X7OWJOVZNYSRAOXXJWW4K6G\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662515466.5_warc_CC-MAIN-20220516235937-20220517025937-00150.warc.gz\"}"}