linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Buesch <mb@bu3sch.de>
To: "Rafał Miłecki" <zajec5@gmail.com>
Cc: bcm43xx-dev@lists.berlios.de,
	"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
	"John W. Linville" <linville@tuxdriver.com>
Subject: Re: [PATCH 3/6] b43: N-PHY: add RSSI calculation for PHY rev < 3
Date: Mon, 11 Jan 2010 23:13:25 +0100	[thread overview]
Message-ID: <201001112313.26197.mb@bu3sch.de> (raw)
In-Reply-To: <b170af451001111313r6bc6905fg722fcd42d7f2681a@mail.gmail.com>

On Monday 11 January 2010 22:13:31 Rafał Miłecki wrote:
> 2010/1/10 Michael Buesch <mb@bu3sch.de>:
> > On Sunday 10 January 2010 23:13:34 Rafał Miłecki wrote:
> >> +     s32 results_min[4];
> >> +     u8 vcm_final[4];
> >> +     s32 results[4][4];
> >> +     s32 miniq[4][2];
> >> +     memset(results_min, 0, sizeof(s32) * 4);
> >> +     memset(vcm_final, 0, sizeof(u8) * 4);
> >> +     memset(results, 0, sizeof(s32) * 4 * 4);
> >> +     memset(miniq, 0, sizeof(s32) * 4 * 2);
> >
> > Just initialize the variables to zero instead of doing a memset:
> >
> > +       s32 results_min[4] = { 0, };
> > +       u8 vcm_final[4] = { 0, };
> > +       s32 results[4][4] = { 0, };
> > +       s32 miniq[4][2] = { 0, };
> 
> Nice trick, thanks :) Just for two-dimensional arrays I'll have to hack it to:
> s32 results[4][4] = { { 0, }, { 0, }, { 0, }, { 0, } };
> I believe.

No I don't think so.
It's C standard that uninitialized elements on automatic variables are initialized
to zero, _if_ at least one element is initialized to something.
So if you init one element to 0, all others will be 0, too.
I think that should also work for multidimensional arrays. So my example
s32 results[4][4] = { 0, };
should do the right thing. Am I wrong?

Here's a test-program:


mb@maggie:~$ cat t.c
#include <stdio.h>
#include <stdint.h>

int main(void)
{
        int i, j;
        int32_t results[4][4]
#ifdef INIT_IT
= { 0, };
#else
;
#endif

        for (i = 0; i < 4; i++)
                for (j = 0; j < 4; j++)
                        printf("%d\n", results[i][j]);

}
mb@maggie:~$ gcc -o t t.c
mb@maggie:~$ ./t
0
0
0
1
-1077483840
0
0
0
-1077483824
268436224
268536212
0
-1077483776
268436888
268353524
0
mb@maggie:~$ gcc -D INIT_IT -o t t.c
mb@maggie:~$ ./t
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

-- 
Greetings, Michael.

  reply	other threads:[~2010-01-11 22:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-10 22:13 [PATCH 3/6] b43: N-PHY: add RSSI calculation for PHY rev < 3 Rafał Miłecki
2010-01-10 22:38 ` Michael Buesch
2010-01-11 21:13   ` Rafał Miłecki
2010-01-11 22:13     ` Michael Buesch [this message]
2010-01-11 22:19       ` Johannes Berg
2010-01-11 22:23         ` Michael Buesch
2010-01-11 22:27       ` Rafał Miłecki
2010-01-11 22:42         ` Michael Buesch
2010-01-11 22:43           ` Rafał Miłecki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201001112313.26197.mb@bu3sch.de \
    --to=mb@bu3sch.de \
    --cc=bcm43xx-dev@lists.berlios.de \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    --cc=zajec5@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).