如何将C++程序转为Pascal语法

本文详细介绍了如何将C++程序转换为Pascal语法,包括数据类型、关键字、声明、字符串、数组、数值操作、常量、函数与程序、with...do语句、注释、流程控制等方面,并提供了具体的转换规则和示例。转换过程涉及C++的特性如构造函数、类、整数、Delphi特性的转换。通过这个指南,读者将能够理解C++和Pascal之间的主要差异并进行有效的代码转换。
摘要由CSDN通过智能技术生成

如何将C++程序转为Pascal语法
原文出处: by Paul Fulford of Komodo Software
翻译:http://delphi.ktop.com.tw

将C++ 转为 Pascal/Delphi
==============================
目录
概论
数据型态
关键词
叙述结尾
变量宣告
字符串
数组
数值的指定与比较
常数宣告
函数与程序
with ... do叙述
批注
流程控制
对象导向结构
Containers
例外处理
资料流(Streaming)
项目档的设计
如何转换
结论
=================================
概论:
这篇文章的目的是让您了解C++与Object Pascal的不同
也让您能够有能力将C++转为Object Pascal(以下称为OP)
=================================
数据型态
这一章可学到如何将 C++ 的数据型态 转成 OP 的数据型态.
变量宣告时可参考下列对照表
C++ OP 大小 (bytes) 值范围
==================================================================
char ---- 1 -128 to 127
---- char 1 1 ASCII character
int integer 2 -32,768 to 32,767
short ---- 2 -32,768 to 32,767
---- shortint 1 -128 to 127
long longint 4 -2,147,483,647 to 2,147,483,647
unsigned char byte 1 0 to 255
unsigned int word 2 0 to 65,535
unsigned short word 2 0 to 65,535
unsigned long ---- 4 0 to 4,294,967,295

float single 4 3.4E-38 TO 3.4E+38
double double 8 1.7E-308 TO 1.7E+308
long double extended 10 3.4E-4932 TO 3.4E+4932
---- comp 8 1.7E-308 TO 1.7E+308
---- real (for backwards compatibility only -- use double)

void pointer 8 n/a -- an untyped pointer
---- boolean 1 True or False
(C++ may soon have a boolean type)
String ---- a C++ standard object
---- string an array of up to 255 ASCII characters
---- PChar pointer to a null-terminated string
=================================================================

=================================
关键词
C++ 有 59 个关键词, OP 有 60 个关键词. This does not include the many vendor
C++ 大小写有分 OP 大小写不分

C++的关键词
asm auto break case catch cdecl char class const const_cast continue
default delete do double dynamic_cast else enum extern far float for
friend goto huge if inline interrupt int near new operator pascal private
protected public register reinterpret_cast return short signed sizeof
static static_cast struct switch template this throw try typedef typeid
union unsigned virtual void volatile wchar_t while
OP的关键词
and as asm array begin case class const constructor destructor div do
downto else end except exports file finally for function goto if implementation
in inherited inline initialization interface is label library mod nil not
object of or packed procedure program property raise record repeat set shl
shr string then to try type unit until uses var while with xor
=================================
叙述结尾
C++叙述结尾
大部份的叙述都用 ; 号结尾
有一些例外如:
#include
#define MAXNAMELENGTH 35

OP叙述结尾
所有的叙述都用 ; 号结尾
=================================
变量宣告
C++变量宣告
变量名称只有前32个字有效
变量名称宣告可在程序的任何地方宣告(当然,宣告后才可用)
// ... 如在程序中宣告
{
char i;
for (i=0;i<10;i++)
{
char sName[10]; // 在区块中也可宣告变量
int iCount, iLoop, iValToReach;
double dMaxLoan, dTotal;
float fMaxRate = 123.875;
}
}
OP变量宣告
变量名称只有前63个字有效
变量名称要宣告在var之后,且要在function或procedure开始时宣告
不可在区块内宣告变量
如:
function PayBack_d(var dAmount: double): double;
var
iCount, iLoop, iValToReach: in

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值