勇芳软件 发表于 2018-2-27 10:18:21

【VFB】复制C代码(C与FB的差异)(VFB教程3-7)

此处为VisualFreeBasic编程教程(从零开始学或VB进阶)的子章节部分,全部目录点链接。高深的,有料的,大多是C语言,但C语言与B语言的语法相差甚远,我们必须基本了解下就可以无障碍的复制C语言的代码来,自己改B语言使用了。不过有一点好消息,C语言的数据类型,绝大多少可以直接复制来用,不用修改。变量声明C/C++int a;
int a, b, c;
FreeBASIC
dim a as integer
dim as integer a, b, c未初始化的变量int a;------------------------------------
dim a as integer零初始化变量int a = 0;-------------------------------
dim a as integer初始化变量int a = 123;-------------------------------------
dim a as integer = 123数组int a;a = 1;
---------------------------------------
dim a(0 to 3) as integer
a(0) = 1指针int a;int *p;
p = &a;
*p = 123;
-------------------------------------------
dim a as integer
dim p as integer ptr
p=@a
*p = 123结构,用户定义类型struct UDT {int myfield;
}
-------------------------------------
type UDT
   myfield as integer
end typetypedef,别名typedef int myint;------------------------------
type myint as integer结构指针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 );----------------------------------------
function foo( ) as integer函数体int foo( void ) {return 123;
}
---------------------------------
function foo( ) as integer
    return 123
end function过程声明void foo( void );------------------------------
sub foo( )过程体void foo( void ) {}
----------------------------------
sub foo( )
end subByval参数void foo( int param );foo( a );
-------------------------------------------
sub foo( byval param as integer )
foo( a )byref参数void foo( int *param );foo( &a );

void foo( int& param );
foo( a );
---------------------------------
sub foo( byref param as integer )
foo( a )语句分隔符;   分号----------------------------------
:   冒号for循环for (int i = 0; i < 10; i++) {...
}
-----------------------------------
for i as integer = 0 to 9   还可以带声明 I 的,省了 DIM i as integer
...
nextwhile循环while (condition) {...
}
-------------------------------
while condition
...
wenddo-while循环do {...
} while (condition);
--------------------------------------
do
...
loop while conditionIF ELSEif (condition) {...
} else if (condition) {
...
} else {
...
}
-------------------------------------
if condition then
...
elseif condition then
...
else
...
end if切换,选择switch (a) {case 1:
...
break;
case 2:
case 3:
...
break;
default:
...
break;
}
----------------------------------
select case a
case 1
...


case 2, 3
...

case else
...

end select字符串文字,字符串char *s = "Hello!";char s[] = "Hello!";
-----------------------------------------------
dim s as zstring ptr = @"Hello!"
dim s as zstring * 6+1 = "Hello!"调试输出#include <stdio.h>int main() {
printf("Hello!\n");
return 0;
}
-------------------------------
print "Hello!"注释// foo/* foo */
------------------------------------
' foo
/' foo '/编译时检查#if a #elif b
#else
#endif
------------------------------------------
#if a
#elseif b
#else
#endif编译时目标系统检查#ifdef _WIN32--------------------------------------------
#ifdef __FB_WIN32__模块/头文件名foo.c, foo.h---------------------------------------------
foo.bas, foo.bi典型的编译器命令创建可执行文件gcc foo.c -o foo-----------------------------------
fbc foo.bas




xiawan 发表于 2022-5-17 10:28:45


啥也不说了,感谢楼主分享哇!
页: [1]
查看完整版本: 【VFB】复制C代码(C与FB的差异)(VFB教程3-7)