FreeBASIC マニュアルのトップに戻る

FreeBASIC TblComparisonC

目次→テーブル→Comparison of C/C++ and FreeBASIC←オリジナル・サイト

C/C++ と FreeBASIC の比較 左にメニュー・フレームが表示されていない場合は、ここをクリックして下さい

←リンク元に戻る プログラム開発関連に戻る


C/C++
FreeBASIC


変数の宣言
int a;
int a, b, c;
dim a as long
dim as long a, b, c


初期化されていない変数
int a;
dim a as long = any


0 で初期化された変数
int a = 0;
dim a as long


初期化された変数
int a = 123;
dim a as long = 123


配列
int a[4];
a[0] = 1;
dim a(0 to 3) as long
a(0) = 1


ポインタ
int a;
int *p;
p = &a;
*p = 123;
dim a as long
dim p as long ptr
p = @a
*p = 123


構造、ユーザー定義型
struct UDT {
int myfield;
}
type UDT
myfield as long
end type


typedef, 型の別名
typedef int myint;
type myint as long


struct ポインタ
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


関数の宣言
int foo( void );
declare function foo( ) as long


関数本体
int foo( void ) {
return 123;
}
function foo( ) as long
return 123
end function


sub 宣言
void foo( void );
declare sub foo( )


sub 本体
void foo( void ) {
}
sub foo( )
end sub


byval パラメータ
void foo( int param );
foo( a );
declare sub foo( byval param as long )
foo( a );


パラメータへの byval ポインタ
void foo( int *param );
foo( &a );
declare sub foo( byval param as long ptr )
foo( @a )


byref パラメータ
void foo( int& param );
foo( a );
declare sub foo( byref param as long )
foo( a )



命令の分離子
;
:
<end-of-line>


for ループ
for (int i = 0; i < 10; i++) {
...
}
for i as long = 0 to 9
...
next


while ループ
while (condition) {
...
}
while condition
...
wend


do-while ループ
do {
...
} while (condition);
do
...
loop while condition


if ブロック
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__


module/header ファイル名
foo.c, foo.h
foo.bas, foo.bi


実行ファイルを作る、典型的なコンパイラ命令
gcc foo.c -o foo
fbc foo.bas


目次に戻る

←リンク元に戻る プログラム開発関連に戻る

最終、2018年4月6日に MrSwiss がレビューしました。注:Integer を Long に変更しました(必要な場合)。

ページ歴史:2020-08-22 15:44:57
日本語翻訳:WATANABE Makoto、原文著作者:DkLwikki

ホームページのトップに戻る

表示-非営利-継承