C Masked Global Variable
1
Name:
Anonymous
2009-05-14 5:52
How would I access the global variable tim from procedure()?
int tim = 0;
void procedure(int tim)
{
global tim = local tim;
}
2
Name:
Anonymous
2009-05-14 5:56
DON'T HELP HIM!!!
3
Name:
Anonymous
2009-05-14 6:13
never mind, i'll just rename it then
4
Name:
Anonymous
2009-05-14 6:42
int tim = 0;
void procedure(int tim)
{
//Code here using tim
}
procedure(tim);
5
Name:
Anonymous
2009-05-14 7:03
But how would i access the global variable tim from inside procedure?
e.g. in a C++ class, it would be like this:
class Jobby{
int tim = 0;
public void procedure(int tim)
{
this.tim = tim;
// global = local
}
}
6
Name:
Anonymous
2009-05-14 7:03
>>5
Sorry, i meant, how would i do that in C?
7
Name:
Anonymous
2009-05-14 7:07
You wouldn't. You can't have duplicate variable names like that.
8
Name:
Anonymous
2009-05-14 7:07
Right, thanks
That is all.
9
Name:
Anonymous
2009-05-14 7:08
int(tim)=0;void(procedure)(int(tim)){int(tom)=tim;extern(tim);tim=tom;}
10
Name:
Anonymous
2009-05-14 7:50
who is tim
11
Name:
Anonymous
2009-05-14 7:57
my friendly variable
12
Name:
Anonymous
2009-05-14 8:00
>>9
gcc doesn't like externing tim, i think
13
Name:
Anonymous
2009-05-14 8:02
int tim = 0;
int *tom (int tum) {
tim++;
*tom (tim) = tum;
return tim;
}
tim = tom (tim);
14
Name:
Anonymous
2009-05-14 8:03
It's short for time, but EXPERT C PROGRAMMERS should never use more than 1 character for their variable names.
15
Name:
Anonymous
2009-05-14 9:08
>>14
what about when you run have more than like 55 variables
16
Name:
Anonymous
2009-05-14 9:14
>>15
all variables should be local anyway
17
Name:
Anonymous
2009-05-14 9:22
>>16
get out,
NON-EXPERT PROGRAMMER
18
Name:
Anonymous
2009-05-14 10:28
>>16
avoid global variables whenever possible
19
Name:
Anonymous
2009-05-14 10:37
>>14
Even though this
should be completely absurd, it's terrifying how prevalent it is in the biggest open source projects.
In other words, not only does open source promote communism,
it also supports TERRORISTS!
20
Name:
Anonymous
2009-05-14 12:01
All function should e local as well, so use where and let in functional codans, and define all functions inside the main function in languages like PASCAL.
21
Name:
Anonymous
2011-02-02 23:06
22
Name:
Anonymous
2011-02-03 4:17