Correct way to map C #define to version

Regan Heath regan at netmail.co.nz
Mon Oct 22 05:44:33 PDT 2012


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

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d-learn mailing list