M
Michael B Allen
Which style of local variable declaration do you prefer; put everything
at the top of a function or only within the block in which it is used?
For example;
void
fn(struct foo *f, int bar)
{
struct abc d;
int i;
abc_init(&d);
for (i = 0; i < bar; i++) {
unsigned long num;
struct eee *e;
for (e = f->a; e < f->alim; e++) {
time_t time time_now;
struct tm tm_now;
struct blah b;
...
OR
void
fn(struct foo *f, int bar)
{
struct abc d;
int i;
unsigned long num;
struct eee *e;
time_t time time_now;
struct tm tm_now;
struct blah b;
abc_init(&d);
for (i = 0; i < bar; i++) {
for (e = f->a; e < f->alim; e++) {
...
I've tended to use the second form based on the belief that frequent
movement of the stack pointer would lead to inefficiencies but I have no
idea if my instinct is true.
Mike
at the top of a function or only within the block in which it is used?
For example;
void
fn(struct foo *f, int bar)
{
struct abc d;
int i;
abc_init(&d);
for (i = 0; i < bar; i++) {
unsigned long num;
struct eee *e;
for (e = f->a; e < f->alim; e++) {
time_t time time_now;
struct tm tm_now;
struct blah b;
...
OR
void
fn(struct foo *f, int bar)
{
struct abc d;
int i;
unsigned long num;
struct eee *e;
time_t time time_now;
struct tm tm_now;
struct blah b;
abc_init(&d);
for (i = 0; i < bar; i++) {
for (e = f->a; e < f->alim; e++) {
...
I've tended to use the second form based on the belief that frequent
movement of the stack pointer would lead to inefficiencies but I have no
idea if my instinct is true.
Mike