-3

There is one line of C++ code shown below.

return ::as_Register(value() >> 1);

I just want to know what's the meaning of the '::' which has nothing before it.

Is it the C++ syntax? Can there be nothing before '::'? Such as return ::myMalloc(size)?

The code is from jdk8 openjdk/hotspot/src/cpu/x86/vm/vmreg_x86.inline.hpp.

I am deeply studying the JDK.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
yangyixiaof
  • 225
  • 4
  • 15

2 Answers2

3

A :: references the global namespace:

void bar();

namespace some_namespace
{
    void bar();

    void foo()
    {
        // writing bar() would call some_namespace::bar()
        // but if we want to call the global bar() we have to write:
        ::bar();
    }
}
Horstling
  • 2,131
  • 12
  • 14
1

It's C++. It means that you import this function from other namespaces.

Example:

namespace foo {
  void bar();
}

void bar();

namespace foo {
  void foobar()
  {
    bar(); // Means foo::bar()
    ::bar(); // Means bar() outside foo namespace
  }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
alkino
  • 760
  • 6
  • 15
  • Thank you!your answer is excellent,but I can only choose one correct answer,so I feel very sorry not to give you the correct answer.At last,very thanks to your help.@alkino – yangyixiaof Sep 14 '14 at 14:08