Skip to content

Commit 5e8dd5a

Browse files
committed
docs: add documentation for typedef support in C struct parsing
1 parent 46e2d14 commit 5e8dd5a

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

docs/advanced/c_parser.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,40 @@ t = definition_to_type("""
9494

9595
The last struct in the definition is returned. All previous structs are cached and available for forward references.
9696

97+
## Typedefs
98+
99+
The parser supports `typedef` declarations. Typedefs are resolved when used as field types in subsequent structs:
100+
101+
```python
102+
t = definition_to_type("""
103+
typedef unsigned int uint32_t;
104+
struct S { uint32_t x; };
105+
""")
106+
```
107+
108+
Struct typedefs, pointer typedefs, and chained typedefs all work:
109+
110+
```python
111+
# Struct typedef
112+
t = definition_to_type("""
113+
typedef struct { int x; int y; } Point;
114+
struct S { Point p; };
115+
""")
116+
117+
# Pointer typedef
118+
t = definition_to_type("""
119+
typedef int *intptr;
120+
struct S { intptr p; };
121+
""")
122+
123+
# Chained typedef
124+
t = definition_to_type("""
125+
typedef unsigned int u32;
126+
typedef u32 mytype;
127+
struct S { mytype x; };
128+
""")
129+
```
130+
97131
## Include Directives
98132

99133
The parser supports `#include` directives by running the C preprocessor:

0 commit comments

Comments
 (0)