Skip to content
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

Improve translate-c macro @compileErrors for pragma operators #20405

Open
kj4tmp opened this issue Jun 23, 2024 · 3 comments
Open

Improve translate-c macro @compileErrors for pragma operators #20405

kj4tmp opened this issue Jun 23, 2024 · 3 comments
Labels
error message This issue points out an error message that is unhelpful and should be improved. translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@kj4tmp
Copy link
Contributor

kj4tmp commented Jun 23, 2024

Zig Version

0.14.0-dev.66+1fdf13a14

Steps to Reproduce and Observed Behavior

possibly related to #4754

create c file with:

#ifndef PACKED
#define PACKED_BEGIN __pragma(pack(push, 1))
#define PACKED
#define PACKED_END __pragma(pack(pop))
#endif

Observed behavior:

zig translate-c src/test-translate.c

outputs:

pub const PACKED_BEGIN = @compileError("unable to translate macro: undefined identifier `__pragma`");
// src/test-translate.c:2:9
pub const PACKED = "";
pub const PACKED_END = @compileError("unable to translate macro: undefined identifier `__pragma`");
// src/test-translate.c:4:9

Context: I am attempting to use zig to wrap and use https://github.com/OpenEtherCATsociety/SOEM
which uses this macro a lot to create packed structs like:

PACKED_BEGIN
typedef struct PACKED
{
   uint16    comm;
   uint16    addr;
   uint16    d2;
} ec_eepromt;
PACKED_END

Expected Behavior

I would have expected zig to handle this macro and create packed structs.
Someone more knowledgeable should define what should be expected with C packed structs (Zig packed structs are not the same as C packed structs)

@kj4tmp kj4tmp added the bug Observed behavior contradicts documented or intended behavior label Jun 23, 2024
@Vexu
Copy link
Member

Vexu commented Jun 24, 2024

Those pragma macros are untranslatable to Zig since Zig doesn't have pragmas or other annotations like that and the rest of the issue is duplicate of #4754

@Vexu Vexu added translate-c C to Zig source translation feature (@cImport) error message This issue points out an error message that is unhelpful and should be improved. and removed bug Observed behavior contradicts documented or intended behavior labels Jun 24, 2024
@Vexu Vexu added this to the 0.15.0 milestone Jun 24, 2024
@Vexu Vexu changed the title translate-c does not support __pragma Improve translate-c macro @compileErrors for pragma operators Jun 24, 2024
@Srekel
Copy link

Srekel commented Oct 6, 2024

Those pragma macros are untranslatable to Zig since Zig doesn't have pragmas or other annotations like that and the rest of the issue is duplicate of #4754

Sorry if I'm being dumb but just to be clear, is the intent not to support them (thinking primarily of pragma pack here) in Zig, and use compile errors if it spots them in a C header?

@Vexu
Copy link
Member

Vexu commented Oct 9, 2024

I meant that the pragma operator cannot be translated in a way where you'd be able to use PACKED_BEGIN in Zig code but if you have a C file that uses it then translate-c should notice it and add the proper alignments to the struct fields.

And this issue can be closed when PACKED_BEGIN has an error that explains the situation better than undefined identifier '__pragma'.

@Vexu Vexu modified the milestones: 0.15.0, 1.0.0 Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved. translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

No branches or pull requests

3 participants