Re: [Vala] Name clashes in generated C code



On Mon, Dec 27, 2010 at 13:46:47 -0800, Anatol Pomozov wrote:
Hi,

I have a simple Vala program

public struct Struct { string name; }
public enum Type { STRUCT }

[...]
The problem here a name clash in generated Vala code - TYPE_STRUCT
both generated as type of Struct

#define TYPE_STRUCT (struct_get_type ())

and as a enum value

typedef enum  {
    TYPE_STRUCT
} Type;

what is the best way to avoid such clashes?

Well, it depends on whether you are writing a library or an application.

For library the API should be usable from C, so best way is just to avoid
calling the enum 'Type'. For an application the C names don't matter though,
so you can just tell vala to use different one in C.

Is it possible to change enum names to something else.

Try using the [CCode(cprefix=...)] annotation. You'll find examples in the
.vapi files. It's normally used to tell vala how externally provided things
are called, but it should work for renaming things generated by vala too.

I can change enum name from Type to something else e.g. RecordType, but
I would like to know if there is a better solution.

As I say, it depends on whether somebody will be using the API from C or not.
If they will, rename the type. If not, rename the members with cprefix.

-- 
                                                 Jan 'Bulb' Hudec <bulb ucw cz>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]