On 12-09-12 04:35 AM, Phani Bhushan Tholeti wrote:
Hi all:
consider following code:
//global scope
int num =0;
void foo(int num, int num1)
{
num=num1; //this is supposed to be for the global variable
Interesting scenario. The num within foo is not the global variable but
the one of local scope.
#include <stdio.h>
int num=0;
void foo(int num)
{
printf("%d\n", num);
}
int main()
{
foo(3);
return 0;
}
The above code prints 3.
In the above code, is there any way I can make gcc throw a warning,
that there are two variables of same name, accessible in the block?
I don't want any workarounds in the code (like changing variable
names, adding prefixes etc).
I compiled my code with "gcc -Wall -Wextra" but the compiler didn't
complain. I understand your question. You ask about how to make gcc
complain in such a scenario which makes sense. What is the bit about
workarounds. Are you also seeking a way to "fix" the code?
SB
--
Mailing list guidelines and other related articles: http://lug-iitd.org/Footer