-
-
Notifications
You must be signed in to change notification settings - Fork 469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] MSVC support #22
Comments
Thanks for opening this one! I had been putting it off until the core implementation stabilized, but we can definitely begin to address each of these
AFAIK there should be a way at the very least for the library syntax to be compatible with both C99 designated initializers as well as C++20 designated initializers. C++20 is much more picky but should be roughly syntax equivalent if the members are in declaration order
Yep nice, should be able to replace this with a
This one should be reasonably easy to As for supporting non C99 versions of C, the best way forward might be to compile clay as a lib and write a second set of macros / declarations that are compatible with C11 etc... 🤔 |
From my investigations so far, it looks like I'm probably going to be able to get it in line with MSVC C++20. Microsoft flavoured C though, might not be possible. I don't think I'm willing to drop to C89 for the whole library just to support those versions on MSVC. Probably would be best in that case to just compile as a lib and link in 👍 |
Follow up: Successfully compiling as C++20 with MSVC here https://github.com/nicbarker/clay/actions/runs/11083013067/job/30796749136 😁 |
I'm going to mark this as completed for now, when clay stabilizes a little more we can reopen a discussion into whether it's worth dropping to C89 for the library itself in order to support C11 and beyond 🙂 |
Yep I've been messing with clay in our engine, it seems fine so far but I haven't done much with it yet |
@mikejsavage Great, please let me know if you end up building something with it! |
Sorry for necro-bumping but, I was wondering, why C99? If CLAY doesn't have any depedency (not even stdlib as you claimed) and bundles everything it uses why not C89? I know that macros are not quite powerful in C89 as they are in C99, but we can get around that. I write software mainly on C89 for compatibility and portability reasons, and I was thinking of porting CLAY to strict ansi C89 myself (that would be feasible but quite challenging), so if you want help with porting it to C89 (strict or not) I would appreciate to help. I was thinking about making my own layout lib (in C89) to make GUIs with RayLib before I saw your clay video, but know I think it would be better to contribute to this lib and help it reach a more mature state, thanks for the work man, I really do appreciate it. |
@MiraiMindz thanks for reaching out 🙂 |
@nicbarker MSVC does seem to support designated initializer in general (Godbolt). Is there some special kind of syntax/extension required that is unsupported by MSVC? |
@namandixit that is very interesting, I'll have to review and see how close we are or what the specific problems are. It's possible that by getting to c++20 support I actually got closer to msvc C11 / C17 than I realised. |
I'm just trying to compile with MSVC as well and face the same problems. To use packing attributes, they need to be specified in the correct syntax and position:
#pragma pack(push, 1)
typedef enum { // No identifier needed here
// enum values...
} Clay__ElementConfigType;
#pragma pack(pop)
typedef enum __attribute__((packed)) { // Attribute goes here, not an identifier
// enum values...
} Clay__ElementConfigType; If you want to create a cross-platform solution, you would typically define a macro that expands to the appropriate syntax based on the compiler: #ifdef _MSC_VER
#define CLAY_PACKED_ENUM
#define CLAY_PACK_BEGIN #pragma pack(push, 1)
#define CLAY_PACK_END #pragma pack(pop)
#else
#define CLAY_PACKED_ENUM __attribute__((packed))
#define CLAY_PACK_BEGIN
#define CLAY_PACK_END
#endif Then you could use it like this: CLAY_PACK_BEGIN
typedef enum CLAY_PACKED_ENUM {
// enum values...
} Clay__ElementConfigType;
CLAY_PACK_END Maybe this can be somehow added/handled via a generator as well. But, what to do until then? |
I've implemented this based on feedback in #118. |
Yes, sorry, I saw it now. I am looking forward to getting it merged into the master. Will wait so long. |
ERRorBro I am facing the same problem hope we can fix this now |
+1 I'm currently using C++20 and clang-cl, but clang-cl has some issues and prevents me from compiling a static library (not related with clay), so MSVC support would be great |
As of #178 merging, we should have decent MSVC support across the board, including for C99, C11 and C23 via MSVC 🙂 |
Clay currently doesn't compile under MSVC because:
__attribute__((packed))__
CLAY__ALIGNMENT
,#define CLAY__ALIGNMENT(type) _Alignof(type)
works though1 and 2 are not very nice to solve with Microsoft flavoured C, although I will say all of these have direct solutions if you don't mind C++
The text was updated successfully, but these errors were encountered: