OV
OV
CC#
Created by OV on 4/27/2025 in #help
Change the struct size based on current architecture
Hi, I'm working on porting a C library to C# that contains architecture-dependent structs. Here's my C code:
typedef struct windowManager_t {
char *name;
void *window;
...
#ifdef Is64BitEnviroment
unsigned long last_request_read_upper32bit;
unsigned long request_upper;
#endif
void *exithandler;
struct ss_font* global_fonts;
}windowManager_t;
windowManager_t *ss_get_current_window_manager();
typedef struct windowManager_t {
char *name;
void *window;
...
#ifdef Is64BitEnviroment
unsigned long last_request_read_upper32bit;
unsigned long request_upper;
#endif
void *exithandler;
struct ss_font* global_fonts;
}windowManager_t;
windowManager_t *ss_get_current_window_manager();
the problem is that my struct has conditional fields that only exist in 64-bit builds. In C, this is handled with #ifdef Is64BitEnviroment, but I need a C# equivalent that works with "Any CPU" configuration. i tried to copy some runtime code on the same topic. which was the Intptr struct. but it did not work. for my 64 bit windows pc with Any Cpu configuration. it produce the 32 bit (x86) code . How can I define a C# struct that correctly matches this architecture-dependent C struct when compiling with "Any CPU"?
102 replies