On Sep 12, 2012 2:06 PM, "Phani Bhushan Tholeti" <[email protected]> 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 > //other code > return; > } > sorry but it is not for the global variable, the moment you call function foo the arguments are called by value and thus local variables are created in the foo function's stack. so every time you use num and num1 they represent local variable of foo.
if you would not have declared the *int num* in the arguments then num was used as global variable. > 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? no, AFAIK there is not. > I don't want any workarounds in the code (like changing variable > names, adding prefixes etc). > > In the meantime, I am trying the GCC man pages, but they are too long > for me to read through (will complete it though). If I find any such > flag I'll reply to this mail. surely i too will look for this. > > -- > Lots o' Luv, > Phani Bhushan > > Let not your sense of morals prevent you from doing what is right - > Isaac Asimov (Salvor Hardin in Foundation and Empire) > > Please avoid sending me Word or PowerPoint attachments. > See http://www.gnu.org/philosophy/no-word-attachments.html > > -- > Mailing list guidelines and other related articles: http://lug-iitd.org/Footer -- Mailing list guidelines and other related articles: http://lug-iitd.org/Footer
