[PATCH] v4l2.c: add decoding for VIDIOC_CREATE_BUFS's arg.

Philippe De Muyter phdm at macqel.be
Fri Apr 17 10:47:10 UTC 2015


On Thu, Apr 16, 2015 at 09:56:30PM +0300, Dmitry V. Levin wrote:
> On Thu, Apr 16, 2015 at 03:33:34PM +0200, Philippe De Muyter wrote:
> > +		else {
> > +			static char fmt[] = "{index=%u, count=%u}";
> 
> This fmt does not have to be static.
> 
> > +			static char outstr[sizeof(fmt) + sizeof(int) * 6];
> > +
> > +			sprintf(outstr, fmt, b.index, b.count);
> > +			tcp->auxstr = outstr;
> > +			return 1 + RVAL_STR;

The 'static' attributes makes the binary smaller.  Try this for yourself :

$ cat usestatic.c
#include <stdio.h>

char *usestatic(int index, int count)
        {
        static char fmt[] = "{index=%u, count=%u}";
        static char outstr[sizeof(fmt) + sizeof(int) * 6];

        sprintf(outstr, fmt, index, count);
        return outstr;
        }
$ cat dontusestatic.c
#include <stdio.h>

char *dontusestatic(int index, int count)
        {
        char fmt[] = "{index=%u, count=%u}";
        static char outstr[sizeof(fmt) + sizeof(int) * 6];

        sprintf(outstr, fmt, index, count);
        return outstr;
        }
$ gcc -O2 -c usestatic.c
$ gcc -O2 -c dontusestatic.c
$ size usestatic.o dontusestatic.o

on i586 :
   text    data     bss     dec     hex filename
     47      21      45     113      71 usestatic.o
    117       0      45     162      a2 dontusestatic.o

on arm :
   text    data     bss     dec     hex filename
     44      24      48     116      74 usestatic.o
    112       0      48     160      a0 dontusestatic.o

I should even add the 'const' qualifier to put the string in the
'text' segment.

Philippe

-- 
Philippe De Muyter +32 2 6101532 Macq SA rue de l'Aeronef 2 B-1140 Bruxelles




More information about the Strace-devel mailing list