Constructor for structs in C

前端 未结 6 1283
南旧
南旧 2021-02-01 01:48

Given:

struct objStruct {
    int id;
    int value;
};

typedef struct objStruct Object;

Is there a shortcut to allocate and initialize the ob

6条回答
  •  我在风中等你
    2021-02-01 02:42

    If you are looking for an object oriented "emulation" over C, I strongly recommend the GObject Type System [1], it's mature and largely used by GTK for instance.

    GLib [2] has also a nice slice allocator for small objects, currently used by GNOME.

    [1] GObject Reference Manual

    [2] GLib Memory Slices

提交回复
热议问题