└── README.md /README.md: -------------------------------------------------------------------------------- 1 | Pascal for C users 2 | ================== 3 | 4 | **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. 5 | 6 | | C | [Pascal](https://wiki.freepascal.org/Pascal "Pascal") | Notes | 7 | | --- | --- | --- | 8 | | { | [Begin](https://wiki.freepascal.org/Begin "Begin") | | 9 | | } | [End](https://wiki.freepascal.org/End "End") | | 10 | | = | := | [Becomes](https://wiki.freepascal.org/Becomes "Becomes") | 11 | | == | = | [Equal](https://wiki.freepascal.org/Equal "Equal") | 12 | | / | / | [Float Division](https://wiki.freepascal.org/Slash "Slash") (Integer: [div](https://wiki.freepascal.org/Div "Div")) | 13 | | % | [Mod](https://wiki.freepascal.org/Mod "Mod") | Modulo operation | 14 | | ! | [Not](https://wiki.freepascal.org/Not "Not") | Logical not | 15 | | != | <> | [Not equal](https://wiki.freepascal.org/Not_equal "Not equal") | 16 | | && | [And](https://wiki.freepascal.org/And "And") | Logical and | 17 | | \| | [Or](https://wiki.freepascal.org/Or "Or") | Logical or | 18 | | & | [And](https://wiki.freepascal.org/And "And") | Bitwise and | 19 | | \| | [Or](https://wiki.freepascal.org/Or "Or") | Bitwise or | 20 | | ^ | [Xor](https://wiki.freepascal.org/Xor "Xor") | Exclusive or | 21 | | ~ | [Not](https://wiki.freepascal.org/Not "Not") | One's complement | 22 | | >\> | [Shr](https://wiki.freepascal.org/Shr "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. | 23 | | << | [Shl](https://wiki.freepascal.org/Shl "Shl") | bit shift left | 24 | | \+\+ | [Inc](https://wiki.freepascal.org/Inc "Inc") | | 25 | | \-\- | [Dec](https://wiki.freepascal.org/Dec "Dec") | | 26 | | /\* | { or (* | [Comment](https://wiki.freepascal.org/Comments "Comments") start | 27 | | */ | } or *) | Comment end | 28 | | // | // | End of line comment (only one line comment) | 29 | | 0x | [$](https://wiki.freepascal.org/Dollar_sign "Dollar sign") | prefix for hex-number e.g. $FFFFFF | 30 | | 0 | [&](https://wiki.freepascal.org/%26 "&") | prefix for oct-number e.g. &77777777 | 31 | | 0b | [%](https://wiki.freepascal.org/Percent_sign "Percent sign") | prefix for bin-number e.g. %11111111 | 32 | | & | [@](https://wiki.freepascal.org/@ "@") | [address operator](https://wiki.freepascal.org/@ "@") | 33 | | \* | [ ^ ](https://wiki.freepascal.org/%5E"^") | See [Pointer](https://wiki.freepascal.org/Pointer "Pointer") and [Pointers](https://wiki.freepascal.org/Pointers "Pointers") | 34 | | ? |[IfThen](https://www.freepascal.org/docs-html/rtl/math/ifthen.html) | Ternary operator. see [Math](https://www.freepascal.org/docs-html/rtl/math/index-5.html) (min = (a < b) ? a : b) | 35 | | if() | [If](https://wiki.freepascal.org/If "If") [Then](https://wiki.freepascal.org/Then "Then") | | 36 | | if() else | [If](https://wiki.freepascal.org/If "If") [Then](https://wiki.freepascal.org/Then "Then") [Else](https://wiki.freepascal.org/Else "Else") | | 37 | | while | [While](https://wiki.freepascal.org/While "While") [Do](https://wiki.freepascal.org/Do "Do") | | 38 | | do while | [Repeat](https://wiki.freepascal.org/Repeat "Repeat") [Until](https://wiki.freepascal.org/Until "Until") [Not](https://wiki.freepascal.org/Not "Not") | | 39 | | do while ! | [Repeat](https://wiki.freepascal.org/Repeat "Repeat") [Until](https://wiki.freepascal.org/Until "Until") | | 40 | | for ++ | [For](https://wiki.freepascal.org/For "For") [To](https://wiki.freepascal.org/To "To") [Do](https://wiki.freepascal.org/Do "Do") | | 41 | | for -- | [For](https://wiki.freepascal.org/For "For") [Downto](https://wiki.freepascal.org/Downto "Downto") [Do](https://wiki.freepascal.org/Do "Do") | | 42 | | switch case break | [Case](https://wiki.freepascal.org/Case "Case") [Of](https://wiki.freepascal.org/Of "Of") [End](https://wiki.freepascal.org/End "End") | | 43 | | switch case break default | [Case](https://wiki.freepascal.org/Case "Case") [Of](https://wiki.freepascal.org/Of "Of") [Else](https://wiki.freepascal.org/Else "Else") [End](https://wiki.freepascal.org/End "End") | | 44 | | const a\_c\_struct *arg | [Constref](https://wiki.freepascal.org/Constref "Constref") arg : a\_c\_struct | | 45 | | a\_c\_struct *arg | [Var](https://wiki.freepascal.org/Var "Var") arg : a\_c\_struct | | 46 | 47 | 48 | 49 | | C type | [Pascal](https://wiki.freepascal.org/Pascal "Pascal") [type](https://wiki.freepascal.org/Data_type "Data type") | Size (bits) | Range | Notes | 50 | | --- | --- | --- | --- | --- | 51 | | char | [Char](https://wiki.freepascal.org/Char "Char") | 8-bit | | [ASCII](https://wiki.freepascal.org/ASCII "ASCII") | 52 | | signed char | [Shortint](https://wiki.freepascal.org/Shortint "Shortint") | 8-bit | -128 .. 127 | | 53 | | unsigned char | [Byte](https://wiki.freepascal.org/Byte "Byte") | 8-bit | 0 .. 255 | | 54 | | char* | [PChar](https://wiki.freepascal.org/PChar "PChar") | (32-bit) | | Pointer to a null-terminated string | 55 | | short int | [Smallint](https://wiki.freepascal.org/Smallint "Smallint") | 16-bit | -32768 .. 32767 | | 56 | | unsigned short int | [Word](https://wiki.freepascal.org/Word "Word") | 16-bit | 0 .. 65535 | | 57 | | int | [Integer](https://wiki.freepascal.org/Integer "Integer") | (16-bit or) 32-bit | -2147483648..2147483647 | Generic integer types | 58 | | unsigned int | [Cardinal](https://wiki.freepascal.org/Cardinal "Cardinal") | (16-bit or) 32-bit | 0 .. 4294967295 | Generic integer types | 59 | | long int | [Longint](https://wiki.freepascal.org/Longint "Longint") | 32-bit | -2147483648..2147483647 | | 60 | | unsigned long int | [Longword](https://wiki.freepascal.org/Longword "Longword") | 32-bit | 0 .. 4294967295 | | 61 | | float | [Single](https://wiki.freepascal.org/Single "Single") | 32-bit | 1.5E-45 .. 3.4E+38 | | 62 | | double | [Double](https://wiki.freepascal.org/Double "Double") | 64-bit | 5.0E-324 .. 1.7E+308 | | 63 | | unsigned long long | [QWord](https://wiki.freepascal.org/QWord "QWord")| 64-bit | 0 .. 18446744073709551615 | 64 | 65 | 66 | | C type | [Pascal](https://wiki.freepascal.org/Pascal "Pascal") | Notes | 67 | | --- | --- | --- | 68 | | struct { } | [Record](https://wiki.freepascal.org/Record "Record") [End](https://wiki.freepascal.org/End "End") | | 69 | | union { } | [Record](https://wiki.freepascal.org/Record "Record") [Case](https://wiki.freepascal.org/Case "Case") [Of](https://wiki.freepascal.org/Of "Of") [End](https://wiki.freepascal.org/End "End") | [Variant Record](https://wiki.freepascal.org/Case#Variant_Record "Case") | 70 | 71 | 72 | 73 | 74 | 75 | | C | [Pascal](https://wiki.freepascal.org/Pascal "Pascal") | [Unit](https://wiki.freepascal.org/Unit "Unit") | 76 | | --- | --- | --- | 77 | | abs | Abs | [System](https://wiki.freepascal.org/System_unit "System unit") | 78 | | acos | ArcCos | [Math](https://wiki.freepascal.org/index.php?title=Math_unit&action=edit&redlink=1 "Math unit (page does not exist)") | 79 | | asin | ArcSin | [Math](https://wiki.freepascal.org/index.php?title=Math_unit&action=edit&redlink=1 "Math unit (page does not exist)") | 80 | | atan | ArcTan | [System](https://wiki.freepascal.org/System_unit "System unit") | 81 | | atof | StrToFloat | [SysUtils](https://wiki.freepascal.org/sysutils "sysutils") | 82 | | atoi | StrToInt | [SysUtils](https://wiki.freepascal.org/sysutils "sysutils") | 83 | | atol | StrToInt | [SysUtils](https://wiki.freepascal.org/sysutils "sysutils") | 84 | | atoll | StrToInt64 | [SysUtils](https://wiki.freepascal.org/sysutils "sysutils") | 85 | | ceil | Ceil | [Math](https://wiki.freepascal.org/index.php?title=Math_unit&action=edit&redlink=1 "Math unit (page does not exist)") | 86 | | cos | Cos | [System](https://wiki.freepascal.org/System_unit "System unit") | 87 | | exp | Exp | [System](https://wiki.freepascal.org/System_unit "System unit") | 88 | | floor | Floor | [Math](https://wiki.freepascal.org/index.php?title=Math_unit&action=edit&redlink=1 "Math unit (page does not exist)") | 89 | | pow | Power | [Math](https://wiki.freepascal.org/index.php?title=Math_unit&action=edit&redlink=1 "Math unit (page does not exist)") | 90 | | round | Round | [System](https://wiki.freepascal.org/System_unit "System unit") | 91 | | sin | Sin | [System](https://wiki.freepascal.org/System_unit "System unit") | 92 | | sqrt | Sqrt | [System](https://wiki.freepascal.org/System_unit "System unit") | 93 | | strcpy | Copy | [System](https://wiki.freepascal.org/System_unit "System unit") | 94 | | strlen | Length | [System](https://wiki.freepascal.org/System_unit "System unit") | 95 | | tan | Tan | [Math](https://wiki.freepascal.org/index.php?title=Math_unit&action=edit&redlink=1 "Math unit (page does not exist)") | 96 | | toupper | UpCase | [System](https://wiki.freepascal.org/System_unit "System unit") | 97 | 98 | 99 | **Assignment Operators** 100 | 101 | |Operator C | Description | Example | 102 | | --- | --- | --- | 103 | |= |Simple assignment operator. Assigns values from right side operands to left side operand|C = A + B is equivalent to pascal C:= A + B| 104 | |+=|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 105 | |-=|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| 106 | |*=|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| 107 | |/=|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| 108 | |%=|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| 109 | |&=|Bitwise AND assignment operator.|C &= 2 is equivalent to pascal C := C and 2| 110 | |^=|Bitwise exclusive OR and assignment operator.|C ^= 2 is equivalent to pascal C := C or not 2| 111 | ||= |Bitwise inclusive OR and assignment operator.| C |= 2 is equivalent to pascal C := C or 2| 112 | 113 | ***note:*** in free pascal you may not convert the following operators (+= , -= , *= , /=) 114 | 115 | ### Escape sequences in C 116 | 117 | | Escape sequence | Hex value in ASCII | Character represented | 118 | | --- | --- | --- | 119 | | \? | 3F | Question mark (used to avoid trigraphs)| 120 | | \' | 27 | Apostrophe or single quotation mark| 121 | | \" | 22 | Double quotation mark| 122 | | \\ | 5C | Backslash| 123 | | \a | 07 | Alert (Beep, Bell) (added in C89)| 124 | | \b | 08 | Backspace| 125 | | \e | 1B | Escape character| 126 | | \f | 0C | Formfeed Page Break| 127 | | \n | 0A | Newline (Line Feed); see notes below| 128 | | \nnn | any | The byte whose numerical value is given by nnn interpreted as an octal number| 129 | | \r | 0D | Carriage Return| 130 | | \t | 09 | Horizontal Tab| 131 | | \uhhhh | none | Unicode code point below 10000 hexadecimal (added in C99)[1]: 26|  132 | | \Uhhhhhhhh | none | Unicode code point where h is a hexadecimal digit| 133 | | \v | 0B | Vertical Tab| 134 | | \xhh… | any | The byte whose numerical value is given by hh… interpreted as a hexadecimal number| 135 | 136 | ### C++ 137 | 138 | | C++ type | [Pascal](https://wiki.freepascal.org/Pascal "Pascal") | Notes | 139 | | --- | --- | --- | 140 | | class { } | [Class](https://wiki.freepascal.org/Class "Class") [End](https://wiki.freepascal.org/End "End") | | 141 | | class: { } | [Class](https://wiki.freepascal.org/Class "Class")( ) [End](https://wiki.freepascal.org/End "End") | | 142 | | template <class T> class { } | [Generic](https://wiki.freepascal.org/index.php?title=Generic&action=edit&redlink=1 "Generic (page does not exist)") = [Class](https://wiki.freepascal.org/Class "Class")<T> [End](https://wiki.freepascal.org/End "End") | | 143 | | struct { } | [Object](https://wiki.freepascal.org/Object "Object") [End](https://wiki.freepascal.org/End "End") | If you want methods | 144 | --------------------------------------------------------------------------------