Skip to content

GuvaCode/Pascal-for-C-users

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 

Repository files navigation

Pascal for C users

Note: Logical operators (AND/OR/XOR etc) are logical or boolean depending on the type of the arguments (boolean or integer). Since Pascal had a separate boolean type from the start, boolean operators on integers were not necessary, and are always logical.

C Pascal Notes
{ Begin
} End
= := Becomes
== = Equal
/ / Float Division (Integer: div)
% Mod Modulo operation
! Not Logical not
!= <> Not equal
&& And Logical and
| Or Logical or
& And Bitwise and
| Or Bitwise or
^ Xor Exclusive or
~ Not One's complement
>> Shr bit shift right Note: shr is a logical bitshift, not arithmetic. If the left operand is a negative value of a signed type, then the result of an shr operation may not be what you expect.
<< Shl bit shift left
++ Inc
-- Dec
/* { or (* Comment start
*/ } or *) Comment end
// // End of line comment (only one line comment)
0x $ prefix for hex-number e.g. $FFFFFF
0 & prefix for oct-number e.g. &77777777
0b % prefix for bin-number e.g. %11111111
& @ address operator
* ^ See Pointer and Pointers
? IfThen Ternary operator. see Math (min = (a < b) ? a : b)
if() If Then
if() else If Then Else
while While Do
do while Repeat Until Not
do while ! Repeat Until
for ++ For To Do
for -- For Downto Do
switch case break Case Of End
switch case break default Case Of Else End
const a_c_struct *arg Constref arg : a_c_struct
a_c_struct *arg Var arg : a_c_struct
C type Pascal type Size (bits) Range Notes
char Char 8-bit ASCII
signed char Shortint 8-bit -128 .. 127
unsigned char Byte 8-bit 0 .. 255
char* PChar (32-bit) Pointer to a null-terminated string
short int Smallint 16-bit -32768 .. 32767
unsigned short int Word 16-bit 0 .. 65535
int Integer (16-bit or) 32-bit -2147483648..2147483647 Generic integer types
unsigned int Cardinal (16-bit or) 32-bit 0 .. 4294967295 Generic integer types
long int Longint 32-bit -2147483648..2147483647
unsigned long int Longword 32-bit 0 .. 4294967295
float Single 32-bit 1.5E-45 .. 3.4E+38
double Double 64-bit 5.0E-324 .. 1.7E+308
unsigned long long QWord 64-bit 0 .. 18446744073709551615
C type Pascal Notes
struct { } Record End
union { } Record Case Of End Variant Record
C Pascal Unit
abs Abs System
acos ArcCos Math
asin ArcSin Math
atan ArcTan System
atof StrToFloat SysUtils
atoi StrToInt SysUtils
atol StrToInt SysUtils
atoll StrToInt64 SysUtils
ceil Ceil Math
cos Cos System
exp Exp System
floor Floor Math
pow Power Math
round Round System
sin Sin System
sqrt Sqrt System
strcpy Copy System
strlen Length System
tan Tan Math
toupper UpCase System

Assignment Operators

Operator C Description Example
= Simple assignment operator. Assigns values from right side operands to left side operand C = A + B is equivalent to pascal C:= A + B
+= Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand. C += A is equivalent to pascal C:= C + A
-= Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand. C -= A is equivalent to pascal C := C - A
*= Multiply AND assignment operator. It multiplies the right operand with the left operand and assigns the result to the left operand. C *= A is equivalent to pascal C := C * A
/= Divide AND assignment operator. It divides the left operand with the right operand and assigns the result to the left operand. C /= A is equivalent to pascal C := C / A
%= Modulus AND assignment operator. It takes modulus using two operands and assigns the result to the left operand. C %= A is equivalent to pascal C := C mod A
&= Bitwise AND assignment operator. C &= 2 is equivalent to pascal C := C and 2
^= Bitwise exclusive OR and assignment operator. C ^= 2 is equivalent to pascal C := C or not 2
|= Bitwise inclusive OR and assignment operator. C |= 2 is equivalent to pascal C := C or 2

note: in free pascal you may not convert the following operators (+= , -= , *= , /=)

Escape sequences in C

Escape sequence Hex value in ASCII Character represented
? 3F Question mark (used to avoid trigraphs)
' 27 Apostrophe or single quotation mark
" 22 Double quotation mark
\ 5C Backslash
\a 07 Alert (Beep, Bell) (added in C89)
\b 08 Backspace
\e 1B Escape character
\f 0C Formfeed Page Break
\n 0A Newline (Line Feed); see notes below
\nnn any The byte whose numerical value is given by nnn interpreted as an octal number
\r 0D Carriage Return
\t 09 Horizontal Tab
\uhhhh none Unicode code point below 10000 hexadecimal (added in C99)[1]: 26
\Uhhhhhhhh none Unicode code point where h is a hexadecimal digit
\v 0B Vertical Tab
\xhh… any The byte whose numerical value is given by hh… interpreted as a hexadecimal number

C++

C++ type Pascal Notes
class { } Class End
class: { } Class( ) End
template <class T> class { } Generic = Class<T> End
struct { } Object End If you want methods

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published