Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

Assignment and datatypes – PB Docs 125 – PowerBuilder Library

Assignment and datatypes – PB Docs 125

Assignment and datatypes

General information

Assignment is not part of expression evaluation. In an assignment
statement, the value of an expression is converted to the datatype
of the left-hand variable. In the expression

the datatype of a+b is
determined by the datatypes of a and b.
Then, the result is converted to the datatype of c.

Overflow on assignment

Even when PowerBuilder performs a calculation at high enough
precision to handle the results, assignment to a lower precision
variable can cause overflow, producing the wrong result.

Example 1

Consider this code:

The final value of d is 33000. The calculation
proceeds like this:

  • Convert
    integer a to long

  • Convert integer b to long

  • Add the longs a and b

  • Assign the result to the long d

Because the variable d is a long,
the value 33000 does not cause overflow.

Example 2

In contrast, consider this code with an assignment to an integer variable:

The resulting value of c and e is
-32536. The calculation proceeds like this:

  • Add the integers a and b

  • Assign the result to c

  • Convert integer c to long and
    assign the result to e

The assignment to the integer variable c causes
the long result of the addition to be truncated, causing overflow
and wrapping. Assigning c to e cannot restore
the lost information.


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x