[FFmpeg-devel] [PATCH 0/2] Origin Wing Commander IV video decoder

Måns Rullgård mans
Thu Feb 3 15:27:55 CET 2011


Diego Biurrun <diego at biurrun.de> writes:

> On Thu, Feb 03, 2011 at 01:54:42PM +0000, M?ns Rullg?rd wrote:
>> Benoit Fouet <benoit.fouet at free.fr> writes:
>> > On Thu, 03 Feb 2011 14:02:12 +0100 Diego Biurrun wrote:
>> >> On Thu, Feb 03, 2011 at 01:28:23PM +0100, Benoit Fouet wrote:
>> >> > On Thu, 03 Feb 2011 12:30:17 +0100 Diego Biurrun wrote:
>> >> > > On Thu, Feb 03, 2011 at 10:32:25AM +0100, Kostya wrote:
>> >> > > > +static int xan_unpack_luma(const uint8_t *src, int src_size, uint8_t *dst, int dst_size)
>> >> > > 
>> >> > > Long line; src_size and dst_size should be const.
>> >> > > 
>> >> > > > +   uint8_t *dst_end = dst + dst_size;
>> >> > > > +   const uint8_t *src_end = src + src_size;
>> >> > > 
>> >> > > dst_end should be const as well.
>> >> > > 
>> >> > > > +/* almost the same as in xan_wc3 decoder */
>> >> > > > +static int xan_unpack(uint8_t *dest, int dest_len, const uint8_t *src, int src_len)
>> >> > > 
>> >> > > Long line; dest_len and src_len should be const.
>> >> > 
>> >> > There is very little point in having them const.  Could you clarify why
>> >> > you want them to be?
>> >> 
>> >> I'm somewhat surprised by your question - because they are not changed
>> >> inside the function?  Was there ever another reason to declare something
>> >> const?
>> >
>> > And even though they were changed, why would that matter anyway?
>> > You're passing a value to the function, you don't care about it being
>> > modified or not. Do you really think that that will save 2 registers
>> > (or 2 int in the stack) when compiled with a const?
>> 
>> There is indeed not much point declaring parameter values as const.
>> The only advantage it brings is that the compiler will flag an error
>> if you accidentally modify them.
>
> That's all I was trying to achieve.  Marking as much stuff as possible
> const is a good habit to pick up IMO.

It depends.  Over-zealous application of const to parameter values can
come back to bite you.  Suppose you later want to change the code such
that it does modify the value (still no change visible from the
caller).  Then you must drop the const, and this change can have
cascade effects if dealing with an interface with multiple
implementations, such as through function pointers.  I've been through
all that, and it's not fun.

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list