Linking with FFmpeg

MrOrdinaire mrordinaire at gmail.com
Sun Jan 6 18:31:51 PST 2013


On Sunday, 6 January 2013 at 18:39:32 UTC, Johannes Pfau wrote:
> Am Sun, 06 Jan 2013 09:43:11 -0800
> schrieb Ali Çehreli <acehreli at yahoo.com>:
>
>> 
>> Ali
>> 
>> P.S. To prove the point that that 4 in the signature has no 
>> meaning,
>> I tested the C function also with the following C program:
>
> With C's arrays are pointers thing, that might be true. But the
> signature (and ffmpeg) documentation suggest that the 
> av_image_alloc
> function will always write 4 ubyte* pointers to the pointers 
> parameter.
> So you can't use an array smaller than 4 pointers. You can use 
> more, as
> it doesn't matter for the ABI, but av_image_alloc will only use 
> 4
> pointers.
>
> So I'd argue that ((ubyte*)[4])* is better as a type than 
> ubyte** as it
> allows the D compiler to do more checks. And the Interfacing to 
> C page
> recommends using ref for static arrays instead of a pointer, as 
> that
> allows using the code as in C:
>
> void av_image_alloc(ref (ubyte*)[4]);
> (ubyte*)[4] ptr;
> av_image_alloc(ptr);
>
> void av_image_alloc((ubyte*)[4]*);
> (ubyte*)[4] ptr;
> av_image_alloc(&ptr); //need &
>
> void av_image_alloc(ubyte**);
> (ubyte*)[3] ptr;
> ubyte* test; //overwritten, BUG!
> av_image_alloc(&ptr); //need &, and accepts to small arrays, 
> bug prone

I agree with you.

One quick question, why do you need a pair of parentheses in 
these declarations, ref (ubyte*)[4] and (ubyte*)[4]? The compiler 
doesn't complain if I remove it.


More information about the Digitalmars-d-learn mailing list