You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/en/dev/llcppg.md
+83Lines changed: 83 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -215,6 +215,89 @@ struct struct2 {
215
215
};
216
216
```
217
217
218
+
##### Nested Enum
219
+
220
+
Similar to nested structs, nested enums can also be accessed in the global scope. llcppg handles named nested enums by creating separate type declarations that are accessible globally.
221
+
222
+
###### Anonymous Nested Enum
223
+
224
+
Anonymous nested enums are converted to inline enum constants within the parent struct context, with the enum values defaulting to `c.Int` type.
225
+
226
+
```c
227
+
typedefstruct Config {
228
+
int version;
229
+
enum {
230
+
MODE_DEBUG = 0,
231
+
MODE_RELEASE = 1
232
+
} mode;
233
+
} Config;
234
+
```
235
+
236
+
**Generated Go code**:
237
+
```go
238
+
typeConfigstruct {
239
+
Version c.Int
240
+
Mode c.Int
241
+
}
242
+
243
+
const (
244
+
MODE_DEBUG c.Int = 0
245
+
MODE_RELEASE c.Int = 1
246
+
)
247
+
```
248
+
249
+
###### Named Nested Enum
250
+
251
+
Named nested enums in C are accessible in the global scope, not just within the context of the outer struct. llcppg handles this by creating separate enum type declarations.
252
+
253
+
**Reason**: In C, named nested enums are declared in the global scope and can be used independently. This means the enum type can be used anywhere in the code, not just within the context of the outer struct.
254
+
255
+
**NOTE:** Should we add type alias here in the future? See discussion: [#530](https://github.com/goplus/llcppg/pull/530)
0 commit comments