Lehks
Lehks

Reputation: 3166

Does Visual C++ provide a language construct with the same functionality as `__attribute__((alias))` in GCC?

__attribute__((alias)) means:

alias ("target")

The alias attribute causes the declaration to be emitted as an alias for another symbol, which must be specified. For instance,

  void __f () { /* Do something. */; }
  void f () __attribute__ ((weak, alias ("__f")));

defines f to be a weak alias for __f. In C++, the mangled name for the target must be used. It is an error if __f is not defined in the same translation unit.

Not all target machines support this attribute.

Upvotes: 4

Views: 1321

Answers (1)

P.W
P.W

Reputation: 26800

You can do something like this for C. This is supported for x86 and x64 for msvc v19.15.

#include <stdio.h>

void __f() { puts("This function is aliased"); }

void f();

#pragma comment(linker, "/alternatename:f=__f")

int main()
{
    f();
}

See the compiled demo here.

I have tested this in Visual Studio 2017 with /TC option.

Upvotes: 2

Related Questions