C
C#

Struct with explicit layout

Struct with explicit layout

PPandetthe11/20/2023
Hi, I am using Wintab and I am trying to make packet struct, but I have some problem. In some situations field x is uint but in others it's a int. Is there any option to determine if it's now uint or int or I need to have two fields - uint and int at the same offset
Rreflectronic11/20/2023
there is no harm in just choosing one the physical representation of int and uint are identical. in fact, some mathematical operations like +/-/* are also identical for int and uint (like, they do the same operations on the bits and return the same result) if you use int in your struct, but you know that the number is unsigned in some particular instance, you can just cast it to uint (uint)struct.Count and it will work correctly the cast just affects the interpretation of the value by functions like ToString() and operators like >>--it doesn't actually change the bits
PPandetthe11/20/2023
Oh, thank you Now I have two fields at the same offset in native struct, one int and one uint but for final app I am casting it to long to not overcomplicate it with every time checking if it's uint or int and then casting Do you think that will be fine or it's a terrible idea?
Rreflectronic11/20/2023
well. you definitely have to check wheher it's signed or unsigned before casting to long it makes a big difference, whether the extra bits on top will be 1 (to preserve the negativeness) or 0
PPandetthe11/20/2023
I know
Rreflectronic11/20/2023
it seems fine to do that and then cast to long and just deal with long
PPandetthe11/20/2023
Thank you, that's all information I need

Looking for more? Join the community!

C
C#

Struct with explicit layout

Join Server
Want results from more Discord servers?
Add your server
Recommended Posts
Extending custom WPF controlWhat are my options to extend this TimePicker list element to full height that shows all items? I'm Discord.Net + MagicOnion, hehehHey! So I am working on a discord bot that I want to intergrate into a server using websockets, I fA question for my c# winforms projecthello guys, i have a question about my c# winforms project. So : I have 2 Projects the first ProjecYO I NEED HELP writing a code need advice not for u to write it for mewrite me a c# program that get 3 latters and tell if they are by the order like abc if they are backBlazor ServicesI dont know too much blazor, but I have a .cs file in a /Settings folder, in which I would like to aHow to optimize this?I have following: ```cs using System; namespace SquareCalculus { internal class FigureTriangle In VSCode, SDK not Recognized on ChromeOSHi. I just installed the .NET SDK and the Runtime by following the instructions for Ubuntu on the MiNito.AsyncEx vs DotNext.ThreadingWe're currently searching for a nice AsyncAutoResetEvent implementation. We found two suitable impleSequential BlinkersHello everyone! I bought these sequential blinkers that run off an stm32 blue pill board. the only pTrying to use Microsoft.Kiota namespace but not found when importingI am trying to use this method from the Microsoft.Kiota.Abstractions.Extensions namespace: ToFirstChWinUI3 Scheduler CalendarViewhello im trying to make a winui3 calendarview interactive calendar where I can predefine dates in myThe call is ambiguous between the following methods or properties: 'Thread.Thread(ThreadStart)' andi have to upload by filesHelp a noobie out with a simple hangmanHi! New to coding and I need some help to solve this problem. Shall I save the words to a list? AnyC# Image Resizing on Visual Studio CodeI've tried both ``newPic.SizeMode = PictureBoxSizeMode.StretchImage;`` and ``newPic.SizeMode = PictuI'm stuck,visual studio 22, I need help making my invaders/enemies move left to right then downI’m trying to get my invaders/enemies to move left to right then down like in the game space invader✅ Where should I store all the sensitive file on .NET project?Hello everyone, May I know where should I store all the credential files that needs to be used by .Unity CodeI have been trying to get my C# code to work in unity for about a week and I am officially lost. I'vHelp! Reporting service in dotnet Core?please don't mind my english, it is not that good. i have created 2 projects one is server -dotnetCatAPI Json deserialization issue.I'm having trouble getting my code to deserialize my json correctly. When I run my Program.cs I get ✅ Any idea why I cant use sendkey?