Re: external and static in c
Posted: Tue Jan 27, 2009 8:53 pm
it might be the f
The Place to Start for Operating System Developers
https://f.osdev.org/
No it doesn't.yemista wrote:well i guess it does work then
Ergo, if some version of some compiler accepts such code, it is a compiler bug, behaviour is undefined, and expect it to be fixed sooner or later.6.7.1 Storage-class specifiers
Syntax
storage-class-specifier:
typedef
extern
static
auto
register
Constaints
At most, one storage-class specifier may be given in the declaration specifiers in a declaration.
It must be because you forgot to declare 'a' static. Also, the value of a is incorrect. Didn't you mean:JamesM wrote:Why doesn't my code compile?
I don't understands!Code: Select all
const volatile int a = 3.1415f;
Kthx.
Code: Select all
a = 1.337
To add my answer(s) to this rhetorical question:JamesM wrote:Why doesn't my code compile?
Oh yeah? Well... you... look funny!Solar wrote:To add my answer(s) to this rhetorical question:JamesM wrote:Why doesn't my code compile?
1) It does compile, setting a to 3.
2) If you meant to point out the uselessness of the declaration, be informed that the ISO standard actually quotes an "extern const volatile int real_time_clock" in an example. (Might be modified by hardware, but not the program.)
Shrek wrote:hi,
do you really think he is serious
If yes , I cant stop laughing .
Regards
Shrek
berkus wrote:Just to throw a little bit of seriousness into the discussion:
Code: Select all
[berkus@aramaki]$ cat aaa.cpp extern static int foobar; static extern int boofar; [berkus@aramaki]$ gcc aaa.cpp -c aaa.cpp:2: error: conflicting specifiers in declaration of ‘foobar’ aaa.cpp:3: error: conflicting specifiers in declaration of ‘boofar’ [berkus@aramaki]$ gcc --version gcc (GCC) 4.3.2
Code: Select all
bash-3.2$ cat bbb.cpp
static int foo;
extern int foo;
int main(void) {
return foo;
}
bash-3.2$ gcc bbb.cpp
bash-3.2$ gcc --version
gcc (GCC) 4.3.2 20080827 (alpha-testing) 1
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bash-3.2$
Hi.JamesM wrote:Why doesn't my code compile?
I don't understands!Code: Select all
const volatile int a = 3.1415f;
Kthx.
So that it is global for the current translation unit only. I.e., all the functions in your .c file can use it as a global variable, but it won't show up in the linker symbols.Shrek wrote:What's the point of making a global variable static ?
If you're going to be an anal pedant about a clearly sarcastic comment, you should note that I have no main() definition, nor any scoping block of any sort.Craze Frog wrote:Hi.JamesM wrote:Why doesn't my code compile?
I don't understands!Code: Select all
const volatile int a = 3.1415f;
Kthx.
Your code compiles cleanly. Either you're using a broken compiler or you're just a dumbass. (I pray for the first. )
Code: Select all
[13:01:30] ~/tmp $ cat tmp.c
const volatile int a = 3.1415f;
[13:01:35] ~/tmp $ gcc -o tmp tmp.c
/usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
[13:01:36] ~/tmp $