Thread overview
C to D conversion for function
Apr 29, 2013
Sumit Raja
Apr 29, 2013
Timon Gehr
Apr 29, 2013
1100110
Apr 29, 2013
Timon Gehr
Apr 29, 2013
Sumit Raja
Apr 29, 2013
Timon Gehr
April 29, 2013
Hi,

I wanted some help in converting this

void av_log_ask_for_sample(void *avc, const char *msg, ...) av_printf_format(2, 3);

from C to D.

I don't know what it means or is called in C to start with so I am a bit lost on what to search for.

Thanks

Sumit
April 29, 2013
On 04/29/2013 12:57 PM, Sumit Raja wrote:
> Hi,
>
> I wanted some help in converting this
>
> void av_log_ask_for_sample(void *avc, const char *msg, ...)
> av_printf_format(2, 3);
>
> from C to D.
>
> I don't know what it means or is called in C to start with so I am a bit
> lost on what to search for.
>
> Thanks
>
> Sumit

av_printf_format is a preprocessor macro that expands to a built-in compiler attribute which enables compile-time printf-style format string checking. There is no support for such a feature in any D compiler.

You want

void av_log_ask_for_sample(void* avc, const(char)* msg, ...);


In case you want to preserve the attribute:

struct av_printf_format{ int fmtpos, attrpos; }

@av_printf_format(2, 3) void av_log_ask_for_sample(void* avc, const(char)* msg, ...);

April 29, 2013
On 04/29/2013 06:50 AM, Timon Gehr wrote:
> On 04/29/2013 12:57 PM, Sumit Raja wrote:
>> Hi,
>>
>> I wanted some help in converting this
>>
>> void av_log_ask_for_sample(void *avc, const char *msg, ...)
>> av_printf_format(2, 3);
>>
>> from C to D.
>>
>> I don't know what it means or is called in C to start with so I am a bit lost on what to search for.
>>
>> Thanks
>>
>> Sumit
> 
> av_printf_format is a preprocessor macro that expands to a built-in compiler attribute which enables compile-time printf-style format string checking. There is no support for such a feature in any D compiler.
> 
> You want
> 
> void av_log_ask_for_sample(void* avc, const(char)* msg, ...);
> 
> 
> In case you want to preserve the attribute:
> 
> struct av_printf_format{ int fmtpos, attrpos; }
> 
> @av_printf_format(2, 3) void av_log_ask_for_sample(void* avc,
> const(char)* msg, ...);
> 

What is the difference between const(char)*, and const(char*)?  I have
seen them used pretty much interchangeably...

Are they? Somehow I don't think they are.
April 29, 2013
On 04/29/2013 02:17 PM, 1100110 wrote:
> ...
> What is the difference between const(char)*, and const(char*)?  I have
> seen them used pretty much interchangeably...
>
> Are they? Somehow I don't think they are.
>

Variables of type const(char)* can be mutated, while const(char*) cannot be.

void main(){
    const(char)* a = "123".ptr;
    *a = 2;        // error
    a = "456".ptr; // ok
    const(char*) b = "123".ptr;
    *b = 2;        // error
    b = "456".ptr; // error
}
April 29, 2013
On Monday, 29 April 2013 at 11:50:21 UTC, Timon Gehr wrote:

> In case you want to preserve the attribute:
>
> struct av_printf_format{ int fmtpos, attrpos; }
>
> @av_printf_format(2, 3) void av_log_ask_for_sample(void* avc, const(char)* msg, ...);

Thanks. What does @av_printf_format(2, 3) do to the function?

April 29, 2013
On 04/29/2013 02:24 PM, Sumit Raja wrote:
> On Monday, 29 April 2013 at 11:50:21 UTC, Timon Gehr wrote:
>
>> In case you want to preserve the attribute:
>>
>> struct av_printf_format{ int fmtpos, attrpos; }
>>
>> @av_printf_format(2, 3) void av_log_ask_for_sample(void* avc,
>> const(char)* msg, ...);
>
> Thanks. What does @av_printf_format(2, 3) do to the function?
>

Nothing except attaching a piece of data to it

http://dlang.org/attribute.html#UserDefinedAttribute