IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesC++/CLIOperators  Print This     

Cross Ref > Operators

By Mike Prestwood

C++/CLI versus Delphi Prism: A side by side comparison between C++/CLI and Delphi Prism.

 
Operators
 

A language symbol used for assignment, comparison, computational, or as a logical.

Assignment

[Other Languages] 

Languages Focus

Common assignment operators for languages include =, ==, and :=. An assignment operator allows you to assign a value to a variable. The value can be a literal value like "Mike" or 42 or the value stored in another variable or returned by a function.

C++/CLI:   =

C++/CLI uses = for it's assignment operator.

Syntax Example:
int Age;
string FullName;
  
Age = 42;
FullName = "Randy Spitz";
Delphi Prism:   :=

Same as Delphi.

Syntax Example:
FullName: String;
Age: Integer;
  
FullName := "Randy Spitz";
Age := 38;




Comparison Operators

[Other Languages] 

General Info: Round Floating Point Numbers

When comparing floating point numbers, make sure you round to an acceptable level of rounding for the type of application you are using.

Languages Focus

A comparison operator compares two values either literals as in "Hello" and 3 or variables as in X and Counter. Most languages use the same operators for comparing both numbers and strings. Perl, for example, uses separate sets of comparison operators for numbers and strings.

C++/CLI:   ==, !=

Same as standard C++. Common comparison operators:

== equal
!= not equal
< less than
> greater than
<= less than or equal
>= greater than or equal
Syntax Example:
//Does C++/CLI evaluate the math correctly? No!
if (0.1 + 0.1 + 0.1 == 0.3)
MessageBox::Show("correct");
else
MessageBox::Show("not correct");
Delphi Prism:   =, <>

Same as Delphi. Common comparison operators:

= equal
<> not equal
< less than
> greater than
<= less than or equal
>= greater than or equal
Syntax Example:
//Does Prism evaluate the math correctly? No!
//This is different than later versions of 
//Delphi that muse MaxSingle in math.pas.
If .1 + .1 + .1 = .3 Then
MessageBox.Show("correct")
Else
MessageBox.Show("not correct");




Empty String Check

[Other Languages] 

Languages Focus

An empty string is a zero length string, a string that is equal to null (""), or not assigned. In some languages, you can check if a string is empty by comparing it to an empty string (""). Some languages distinguish between nil and null ("") so checking if the length is 0 is easier.

C++/CLI:   String.IsNullOrEmpty

The .Net framework offers a static method in the string class: String.IsNullOrEmpty.

Syntax Example:
String^ s;
  
//s = ""; //Uncomment to test 2nd case.
  
if (String::IsNullOrEmpty(s))
{
  MessageBox::Show("empty string");
}
Delphi Prism:   length

In Prism, a string can be nil (unassigned), assigned an empty string (""), or assigned a value.  Therefore, to check if a string is empty, you have to check against both nil and (""). Alternatively, you can check the length of the string or use String.IsNullOrEmpty.

Syntax Example:
var s: String; 
 
if (s = nil) or (s = '') then
  MessageBox.Show("empty string");

or use length:

if length(s) = 0 then
  MessageBox.Show("empty string");




Logical Operators

[Other Languages] 

Languages Focus

Logical operators perform conditional and, or, and not operations. Some languages support both binary logical operators that link two and unary logical operators negate (make opposite) the truth value of its argument. Finally, some languages short circuit logic. For example, with this or that, if this is an expression returning true, then that is never executed.

C++/CLI: 

Same as C++ and Java. C# logical operators:

& and, as in this and that No Short Circuit
&& and, as in this and that short circuits
| or, as in this or that No Short Circuit
|| or, as in this or that short circuits
! Not, as in Not This
^ either or, as in this or that but not both

Syntax Example:
//Given expressions a, b, c, and d:
if !((a && b) && (c || d)) {
  //Do something.
}
Delphi Prism: 

Prism logical operators:

and and, as in this and that
or or, as in this or that
not Not, as in Not This
xor either or, as in this or that but not both

Syntax Example:  
//Given expressions a, b, c, and d:
if Not (a and b) and (c or d) then
  //Do something.




String Concatenation

[Other Languages] 
C++/CLI:  "String Concatenation" +

C++/CLI performs implicit casting of numbers to strings. To concatenate two strings, a string to an integer, or a string to a floating point number, use the + operator. For example, to convert a floating point number to a string just concatenate an empty string to the number as in "" + 3.2.

Alternatively, you can use the System.Text.StringBuilder class which frequently but not always provides faster code.

Syntax Example:  
//Implicit casting of numbers.
//
//This fails:
//MessageBox::Show(3.3);
//
//This works:
MessageBox::Show("" + 3.3);
Delphi Prism:   +

Unlike Delphi, Prism performs implicit casting. To concatenate two strings, a string to an integer, or a string to a floating point number, use the + operator. For example, to convert a floating point number to a string just concatenate an empty string to the number as in "" + 3.2.

Alternatively, you can use the System.Text.StringBuilder class which frequently but not always provides faster code.

Syntax Example:
var FirstName : String;
var LastName : String;
  
FirstName := 'Mike';
LastName := 'Prestwood';
ShowMessage('Full name: ' + FirstName + ' ' + LastName);
  
//Implicit casting of numbers.
//
//This fails:
//MessageBox.Show(3.3);
//
//This works:
MessageBox.Show("" + 3.3);




Unary Operators

[Other Languages] 

General Info: Unary Operator

An operation with only one operand (a single input). Common unary operators include + plus, - minus, and bitwise not. Some operators can function as both unary and binary operators. For example, + and - operators can serve as either.

Languages Focus

What unary operators are supported in additoin to the standard plus, minus, and bitwise not.

[Not specified yet. Coming...]
Delphi Prism: 

The obvious Prism unary operators are +, -, and Not.

+ Plus
- Minus
Not Bitwise Not
Inc() Increment
Dec() Decrement

Syntax Example:
var i: Integer := 1;
Inc(i);
MessageBox.Show("" + i);  //Displays 2




Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]