Q: Local variables initialization shortcut.
- From: Jean-Christophe <5.d@xxxxxxx>
- Date: Sat, 2 Jun 2012 02:49:23 -0700 (PDT)
Hi all,
The function f() has some local (double)
which should all be initialized to zero :
a = b = c = ... = y = z = 0.0;
Can I use a shortcut like this :
memset( &a, 0, number_of_variables * sizeof(double) );
If yes, can I do this :
memset( &a, 0, (&z - &a + sizeof(double)) );
Like this :
void f(void)
{
double a,b,c,d,...,x,y,z;
memset( &a, 0, (unsigned int)( &z - &a + sizeof(double) ) );
...
}
--------
PS :
Of course the # of variables is not always 26,
that's why I want an easy way to implement initialization to zero.
.
- Follow-Ups:
- Re: Q: Local variables initialization shortcut.
- From: Noob
- Re: Q: Local variables initialization shortcut.
- From: BartC
- Re: Q: Local variables initialization shortcut.
- From: Jens Thoms Toerring
- Re: Q: Local variables initialization shortcut.
- From: Ian Collins
- Re: Q: Local variables initialization shortcut.
- From: jacob navia
- Re: Q: Local variables initialization shortcut.
- Prev by Date: Re: GOTOs discovered in "real world" program!
- Next by Date: Re: Q: Local variables initialization shortcut.
- Previous by thread: Re: Generic programming in C.
- Next by thread: Re: Q: Local variables initialization shortcut.
- Index(es):
Relevant Pages
|