Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22113

What standard says about anonymous namespace and internal linkage?

$
0
0

I'm curious about this fact as I came up with the following code:

namespace
{
    int my_variable = 12;
    void get_data_a_lot() {}
}


int main()
{
    my_variable++;

    get_data_a_lot();
}

and compiling with msvc I get the following:

00E 00000000 SECT4  notype       External     | ?my_variable@?A0x087c0a53@@3HA (int `anonymous namespace'::my_variable)
025 00000000 SECT6  notype ()    Static       | ?get_data_a_lot@?A0x087c0a53@@YAXXZ (void __cdecl `anonymous namespace'::get_data_a_lot(void))

But when I compile with gcc I get the following:

002 00000000 SECT2  notype       Static       | _ZN12_GLOBAL__N_111my_variableE
003 00000000 SECT1  notype ()    Static       | _ZN12_GLOBAL__N_114get_data_a_lotEv

So the question is: Is it correct behavior that "my_variable" is External or is it compiler bug?


Viewing all articles
Browse latest Browse all 22113

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>