Re: extern
Chris Torek wrote:[color=blue]
> In article <sysDe.184979$7 5.8009312@news4 .tin.it>
> DevarajA <no@spam.com> wrote:
>[color=green]
>>I compiled into an object file (on linux) with:
>>$ gcc a.c -c -o a.obj
>>and then i printed it's symbol table with:
>>$ nm a.obj
>>This is the output:
>>
>>00000000 T main
>>00000004 C var2
>>
>>where "C" means "The symbol is common. ...[/color]
>
>
> The so-called "common model", in which var2 uses this "common
> symbol" trick, is *optional*: C compilers are not required to
> implement one. They may instead use a "def/ref model".
>
> If your C compiler used a def/ref model, the "nm" output for the
> above would give var2 the "D" type. Changing the declaration
> for var2 to "extern int var2" would give it the "U" type.
>
> C compilers on Unix-like systems never use the def/ref model,[/color]
Not true, Chris. If you give gcc the correct command line options on a
Unixlike implementation (Linux) it will not use the common model and
*will* generate an error on linking if a variable is declared twice even
with neither declaration specifying an initialiser.
[color=blue]
> because there are gigabytes of Unix-like-system "freeware" source
> code that *require* common-model. C compilers on some other systems
> *do* use def/ref, and that code fails to compile on them.[/color]
That I can believe, since gcc probably has the same option on non-unix
like systems ;-)
[color=blue]
> (C++
> compilers also do use def/ref, even on Unix-like systems.)[/color]
That I can't comment on.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Chris Torek wrote:[color=blue]
> In article <sysDe.184979$7 5.8009312@news4 .tin.it>
> DevarajA <no@spam.com> wrote:
>[color=green]
>>I compiled into an object file (on linux) with:
>>$ gcc a.c -c -o a.obj
>>and then i printed it's symbol table with:
>>$ nm a.obj
>>This is the output:
>>
>>00000000 T main
>>00000004 C var2
>>
>>where "C" means "The symbol is common. ...[/color]
>
>
> The so-called "common model", in which var2 uses this "common
> symbol" trick, is *optional*: C compilers are not required to
> implement one. They may instead use a "def/ref model".
>
> If your C compiler used a def/ref model, the "nm" output for the
> above would give var2 the "D" type. Changing the declaration
> for var2 to "extern int var2" would give it the "U" type.
>
> C compilers on Unix-like systems never use the def/ref model,[/color]
Not true, Chris. If you give gcc the correct command line options on a
Unixlike implementation (Linux) it will not use the common model and
*will* generate an error on linking if a variable is declared twice even
with neither declaration specifying an initialiser.
[color=blue]
> because there are gigabytes of Unix-like-system "freeware" source
> code that *require* common-model. C compilers on some other systems
> *do* use def/ref, and that code fails to compile on them.[/color]
That I can believe, since gcc probably has the same option on non-unix
like systems ;-)
[color=blue]
> (C++
> compilers also do use def/ref, even on Unix-like systems.)[/color]
That I can't comment on.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Comment