Hirrolot / datatype99

Algebraic data types for C99
MIT License
1.36k stars 23 forks source link

datatype and constructor parameter names #3

Closed picca closed 3 years ago

picca commented 3 years ago

Hello,

I use datatype99 in one of my library, like this

datatype(
    Type,
    (C1, p1_1, p1_2, ... p1_n),
    (C2, p2_1, ...)
);

you get the idea :).

In normal struct you give a name to the parameter, this way it is easy to identify the meaning of each parameter. I can indeeed add after each Constructor a comment describing each parameter. Now my question ism is it possible to give a name to these parameters or embed a comment directly in the definition of the type.

datatype(
     MyType,
     C1( int@n, double@width, ...)
);

or thomething like this.

thanks for your advices.

Cheers

Frederic

Hirrolot commented 3 years ago

You can use typedefs to give meanings to the parameters:

typedef double Width;
typedef double Height;

datatype(
    MyType,
    (C1, Width, Height, ...)
);

Indeed I could implement named parameters in the library itself, but it would complicate the design, so I stick to only unnamed parameters for now.

picca commented 3 years ago

elegant, like your avatar :))