wasabi
wasabi
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
But it's important to understand that IntPtr is a special magic type, as well.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
Ahh. I see what you're referring to. They do use that for the struct declaration. What they do is distribute different versions of System.Private.CoreLib.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
Or are you talking about the PAL stuff?
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
They don't use preprocessors for IntPtr do they?
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
Don't pass structs around. Pass pointers to them. Don't require external users to alloc or free them: provide functions for that.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
Provide functions for all interaction.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
For instance, don't expose the requirement that users know the content/layout of structs.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
But there are lots of ways and examples to write nice good clean C that other people can consume from other platforms.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
And we all periodically suffer because of it.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
Yeah, and as I said, there are non-portable interfaces all over: stat being a big one.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
Because that is the ONE and only one thing that can be both discovered by the runtime, and inferred about external libraries: native pointer size (and to be fair there are even exceptions about that).
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
You have code which is fundamentally a different layout on different architectures. From your little example, actual fields are missing. That means anybody interacting with that interface inherits that burden.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
It's impossible to hide it in any language.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
If you want a portable API that places no burdens on other languages consuming it, that code has to be portable. That means not exposing platform specific things.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
There is no "solving the issue": you wrote crap C code. You have to wrap it with crap C# code.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
With properties and methods.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
Either way, you would usually never make those public. You would make good looking .NET classes public.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
Or you could make two structs for that as well.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
And just cast it.
102 replies
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
You could make that second struct a void* or intptr.
102 replies