All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: initializing a struct
       [not found] <BANLkTimgJN2_SH+_mvkckZKBefCLN6aM=g@mail.gmail.com>
@ 2011-06-30 10:18 ` Vadiraj
  2011-06-30 11:03   ` Michal Nazarewicz
  2011-07-01 17:58   ` Davidlohr Bueso
  0 siblings, 2 replies; 3+ messages in thread
From: Vadiraj @ 2011-06-30 10:18 UTC (permalink / raw)
  To: linux-c-programming

 Hey Guys,
 I'm stuck with logical reason for initializing a struct variable. Please help..
 Consider a struct defined this way..
 struct foo
 {
     int a;
     char *ptr;
 };
 in my function I declare a local variable of this struct.
 void bar()
 {
       struct foo local_var[10];
       ...
       ...
 }
 do you suspect a initialization issue? do we need to initialize the
local array local_var[10] ? What's the best practice?
 Thanks in advance.

 Cheers,
 Vadi
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: initializing a struct
  2011-06-30 10:18 ` initializing a struct Vadiraj
@ 2011-06-30 11:03   ` Michal Nazarewicz
  2011-07-01 17:58   ` Davidlohr Bueso
  1 sibling, 0 replies; 3+ messages in thread
From: Michal Nazarewicz @ 2011-06-30 11:03 UTC (permalink / raw)
  To: linux-c-programming, Vadiraj

On Thu, 30 Jun 2011 12:18:25 +0200, Vadiraj <vadiraj.cs@gmail.com> wrote:
> I'm stuck with logical reason for initializing a struct variable. Please  
> help..
> Consider a struct defined this way..

> struct foo {
>      int a;
>      char *ptr;
> };

> in my function I declare a local variable of this struct.

>  void bar()
>  {
>        struct foo local_var[10];
>        ...
>        ...
>  }

> do you suspect a initialization issue? do we need to initialize the
> local array local_var[10] ?

Yes.  The array has random data.

> What's the best practice?

Uh? Initialise it if you need.

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michal "mina86" Nazarewicz    (o o)
ooo +-----<email/xmpp: mnazarewicz@google.com>-----ooO--(_)--Ooo--

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: initializing a struct
  2011-06-30 10:18 ` initializing a struct Vadiraj
  2011-06-30 11:03   ` Michal Nazarewicz
@ 2011-07-01 17:58   ` Davidlohr Bueso
  1 sibling, 0 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2011-07-01 17:58 UTC (permalink / raw)
  To: Vadiraj; +Cc: linux-c-programming

On Thu, 2011-06-30 at 15:48 +0530, Vadiraj wrote:
> Hey Guys,
>  I'm stuck with logical reason for initializing a struct variable. Please help..
>  Consider a struct defined this way..
>  struct foo
>  {
>      int a;
>      char *ptr;
>  };
>  in my function I declare a local variable of this struct.
>  void bar()
>  {
>        struct foo local_var[10];
>        ...
>        ...
>  }
>  do you suspect a initialization issue? do we need to initialize the
> local array local_var[10] ? What's the best practice?

This kind of initialization is done with memset(), so can use 0s to
avoid random data.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-07-01 17:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <BANLkTimgJN2_SH+_mvkckZKBefCLN6aM=g@mail.gmail.com>
2011-06-30 10:18 ` initializing a struct Vadiraj
2011-06-30 11:03   ` Michal Nazarewicz
2011-07-01 17:58   ` Davidlohr Bueso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.