Demonstrates type punning by interpreting an unsigned byte (`Int8u`) result as a signed byte (`Int8`) to observe how values wrap around.

ID: 431

See: ValueAt
				
					using uCalcSoftware;

var uc = new uCalc();
// Define a variable 'x' that will be used in our expression
var variableX = uc.DefineVariable("x As Int");

// Parse an expression that will result in an unsigned 8-bit integer (0-255)
var parsedExpr = uc.Parse("x + 125", "Int8u");

Console.WriteLine("x | Int8u (0 to 255) | Int8 (-128 to 127)");
Console.WriteLine("------------------------------------------");

for (int x = 1; x <= 5; x++) {
   variableX.ValueInt32(x);

   // Evaluate the expression to get a pointer to the result
   var resultPtr = parsedExpr.EvaluateVoid();

   // Get the raw unsigned result
   var unsignedResult = uc.ValueAt(resultPtr, "Int8u");

   // Use ValueAt to *re-interpret* the same memory as a signed byte
   var signedResult = uc.ValueAt(resultPtr, "Int8");

   Console.WriteLine($"{x} | {unsignedResult} | {signedResult}");
}

// Clean up the created items
parsedExpr.Release();
variableX.Release();
				
			
x | Int8u (0 to 255) | Int8 (-128 to 127)
------------------------------------------
1 | 126 | 126
2 | 127 | 127
3 | 128 | -128
4 | 129 | -127
5 | 130 | -126
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Define a variable 'x' that will be used in our expression
   auto variableX = uc.DefineVariable("x As Int");

   // Parse an expression that will result in an unsigned 8-bit integer (0-255)
   auto parsedExpr = uc.Parse("x + 125", "Int8u");

   cout << "x | Int8u (0 to 255) | Int8 (-128 to 127)" << endl;
   cout << "------------------------------------------" << endl;

   for (int x = 1; x <= 5; x++) {
      variableX.ValueInt32(x);

      // Evaluate the expression to get a pointer to the result
      auto resultPtr = parsedExpr.EvaluateVoid();

      // Get the raw unsigned result
      auto unsignedResult = uc.ValueAt(resultPtr, "Int8u");

      // Use ValueAt to *re-interpret* the same memory as a signed byte
      auto signedResult = uc.ValueAt(resultPtr, "Int8");

      cout << x << " | " << unsignedResult << " | " << signedResult << endl;
   }

   // Clean up the created items
   parsedExpr.Release();
   variableX.Release();
}
				
			
x | Int8u (0 to 255) | Int8 (-128 to 127)
------------------------------------------
1 | 126 | 126
2 | 127 | 127
3 | 128 | -128
4 | 129 | -127
5 | 130 | -126
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Define a variable 'x' that will be used in our expression
      Dim variableX = uc.DefineVariable("x As Int")
      
      '// Parse an expression that will result in an unsigned 8-bit integer (0-255)
      Dim parsedExpr = uc.Parse("x + 125", "Int8u")
      
      Console.WriteLine("x | Int8u (0 to 255) | Int8 (-128 to 127)")
      Console.WriteLine("------------------------------------------")
      
      For x  As Integer = 1 To 5
         variableX.ValueInt32(x)
         
         '// Evaluate the expression to get a pointer to the result
         Dim resultPtr = parsedExpr.EvaluateVoid()
         
         '// Get the raw unsigned result
         Dim unsignedResult = uc.ValueAt(resultPtr, "Int8u")
         
         '// Use ValueAt to *re-interpret* the same memory as a signed byte
         Dim signedResult = uc.ValueAt(resultPtr, "Int8")
         
         Console.WriteLine($"{x} | {unsignedResult} | {signedResult}")
      Next
      
      '// Clean up the created items
      parsedExpr.Release()
      variableX.Release()
   End Sub
End Module
				
			
x | Int8u (0 to 255) | Int8 (-128 to 127)
------------------------------------------
1 | 126 | 126
2 | 127 | 127
3 | 128 | -128
4 | 129 | -127
5 | 130 | -126