Demonstrates type punning by interpreting an unsigned byte (Int8u) result for 255 as a signed byte (Int8) to observe how it wraps around to -1

ID: 1480

See: ValueAt
				
					using uCalcSoftware;

var uc = new uCalc();
var myVar = uc.DefineVariable("counter As Int8u = 255");
var ptr = myVar.ValueAddr();

// Read natively as unsigned byte
Console.WriteLine(uc.ValueAt(ptr, uc.DataTypeOf("Int8u")));

// Read the exact same memory address, but interpret as signed byte
Console.WriteLine(uc.ValueAt(ptr, uc.DataTypeOf("Int8")));
				
			
255
-1
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto myVar = uc.DefineVariable("counter As Int8u = 255");
   auto ptr = myVar.ValueAddr();

   // Read natively as unsigned byte
   cout << uc.ValueAt(ptr, uc.DataTypeOf("Int8u")) << endl;

   // Read the exact same memory address, but interpret as signed byte
   cout << uc.ValueAt(ptr, uc.DataTypeOf("Int8")) << endl;
}
				
			
255
-1
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim myVar = uc.DefineVariable("counter As Int8u = 255")
      Dim ptr = myVar.ValueAddr()
      
      '// Read natively as unsigned byte
      Console.WriteLine(uc.ValueAt(ptr, uc.DataTypeOf("Int8u")))
      
      '// Read the exact same memory address, but interpret as signed byte
      Console.WriteLine(uc.ValueAt(ptr, uc.DataTypeOf("Int8")))
   End Sub
End Module
				
			
255
-1