external and static in c
external and static in c
Does anyone know what the result is of declaring a variable or function static external? What about external static?
Re: external and static in c
Does that even work? They are both linkage declarations so I figure they would conflict and the compiler won't compile the code.
Re: external and static in c
Yes they both work, but I dont know the difference, but there is a difference. External means global and static means local, so together they should conflict but I think it has a special meaning.
Re: external and static in c
hey, im asking the questions here. dont look to me for explanation. What would two opposite keywords make combined?
Re: external and static in c
Berkus' post is a link...yemista wrote:hey, im asking the questions here. dont look to me for explanation. What would two opposite keywords make combined?
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: external and static in c
Do you even know what those keywords mean?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: external and static in c
. If a function is declared as static it cannot be referenced externally , what's the point of your question ?
Regards
Shrek
Regards
Shrek
Re: external and static in c
EDIT: Shrek explains it better below. This post was full of grammatical fail.
Last edited by Hangin10 on Tue Jan 27, 2009 11:28 am, edited 1 time in total.
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: external and static in c
Hi,
extern is used to denote symbols that are not present the current object file and its the duty of the linkage editor (linker ) , to find out the symbol from a different module .
static has two meanings
when used for a variable : The variable maitains its values between function calls , just to give a demonstration , type this program in and find out the output
when used for a function :
when used for a function it means that , function has scope restricted to the given file . It provides some sort of isolation .
However all these are very basic and should not be asked at this level .I now really understand Alboin's and Solar's sentiments. Please read a good C book , then your questions will make more sense .
Regards
Shrek
extern is used to denote symbols that are not present the current object file and its the duty of the linkage editor (linker ) , to find out the symbol from a different module .
static has two meanings
when used for a variable : The variable maitains its values between function calls , just to give a demonstration , type this program in and find out the output
Code: Select all
#include <stdio.h>
#include <stdlib.h>
void func();
int main()
{
func();
func();
func();
}
void func()
{
static int var = 0 ;
var++;
printf("%d \n " , var );
}
when used for a function it means that , function has scope restricted to the given file . It provides some sort of isolation .
However all these are very basic and should not be asked at this level .I now really understand Alboin's and Solar's sentiments. Please read a good C book , then your questions will make more sense .
Regards
Shrek
Re: external and static in c
Doesn't she mean what they mean together? Something like
Which won't compile.
P.S.: I believe I've just advertised foobar2000.
Code: Select all
extern static int foobar;
P.S.: I believe I've just advertised foobar2000.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
Re: external and static in c
Yes I do mean together. And its he. If extern static int foobar wont compile, static extern int foobar will, and Im wondering what that means.
Re: external and static in c
Ok it looks like it wont compile. I dont know wat I was thinking of, but as soon as I find that example ill put it up.
-
- Member
- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
Re: external and static in c
The point is, what the hell does gcc do when you declare the same symbol as both extern and static?Shrek wrote: . If a function is declared as static it cannot be referenced externally , what's the point of your question?
This code is absolute nonsense, yet it compiles cleanly with gcc 4.3.2. At the very least it's nonsense that "static int oups; extern int oups;" compiles while "static extern int oups;" does not.
#include <stdio.h>
static int oups;
extern int oups;
int main (int argc, char *argv[]) {
printf("%d, %d", argc, oups);
return 0;
}
Re: external and static in c
Why doesn't my code compile?
I don't understands!
Kthx.
Code: Select all
const volatile int a = 3.1415f;
Kthx.