Correct way to map C #define to version

Sumit Raja sumitraja at gmail.com
Mon Oct 29 04:31:33 PDT 2012


On Monday, 22 October 2012 at 12:44:35 UTC, Regan Heath wrote:
> On Mon, 22 Oct 2012 12:39:48 +0100, bearophile 
> <bearophileHUGS at lycos.com> wrote:
>
>> Sumit Raja:
>>
>>> Am I using version correctly? How is this done usually?
>>
>> I think "version" is usually meant to be given as compiler 
>> switch. Maybe a simple enum + static if is enough in your case.
>
> Good suggestion.  I was curious so I had a tinker and produced 
> this example which might be useful to you.
>
> import core.stdc.stdint;
> import std.stdio;
>
> enum LIBAVFILTER_VERSION_MAJOR = 2;  	\\ change this to 3 to 
> see a difference in size below
> enum LIBAVFILTER_VERSION_MINOR = 77;
> enum LIBAVFILTER_VERSION_MICRO = 100;
>
> enum FF_API_PACKING = (LIBAVFILTER_VERSION_MAJOR < 3);
>
> struct AVFilterBufferRefAudioProps {
>     uint64_t channel_layout;    ///< channel layout of audio 
> buffer
>     int nb_samples;             ///< number of audio samples 
> per channel
>     int sample_rate;            ///< audio buffer sample rate
> static if(FF_API_PACKING) {
>     int planar;                  ///< audio buffer - planar or 
> packed
> }
> }
>
> void main()
> {
>     writefln("size of AVFilterBufferRefAudioProps = %s", 
> AVFilterBufferRefAudioProps.sizeof);
> }
>
> R

Thanks both this works great for structs. Anything similar I can 
do for enums?


More information about the Digitalmars-d-learn mailing list