Re: xcalloc question

From: Henrik Nordstrom <hno@dont-contact.us>
Date: Wed, 17 Oct 2001 16:32:16 +0200

Alex Rousskov wrote:
>
> On Tue, 16 Oct 2001, Adrian Chadd wrote:
>
> > Here's another cute one - some function parameter declarations
> > "shadow" global declarations, eg time, authScheme.
>
> This is how C is suppose to work. The namespace protection is designed
> so that you do not have to name every variable or formal parameter
> x_my_unique_name_number12345.

True.

To aid developers in not confusing local variables with global variables
modern compilers has the option of warning when a variable shadows
nother one with the same name. This is all about style, not C
compliance.

For our own sake it is beneficial if no shadowing is done in our files.
It makes it easier for us to understand our own code and to debug it.

Consider the following horrible example of fully legal C:

int var;

double func1(double f)
{
    double var = 5.0 * f;
    return var;
}

double func2(double var)
{
    var = var * 2;
    return var;
}

void func3(int i)
{
    var = i;
}

Regards
Henrik
Received on Wed Oct 17 2001 - 08:41:17 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:33 MST