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.
c++ c gcc visual-c++
add a comment |
__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.
c++ c gcc visual-c++
2
Possible duplicate of Does Windows have a __declspec equivalent to Unix GCC's __attribute__((weak))?
– RbMm
Nov 19 '18 at 19:51
1
#pragma comment(linker, "/alternatename:f=__f")
must be (where in place f and __f must be exactly mangled names)
– RbMm
Nov 19 '18 at 19:53
@RbMm: That doesn't look lkke a duplicate.
– R..
Nov 20 '18 at 2:28
@R.. - may be i mistake. however this - stackoverflow.com/a/12397639/6401656 is answer for current question
– RbMm
Nov 20 '18 at 7:19
@RbMm: "same solution works" doesn't imply question is duplicate.
– R..
Nov 20 '18 at 12:30
add a comment |
__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.
c++ c gcc visual-c++
__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.
c++ c gcc visual-c++
c++ c gcc visual-c++
edited Nov 19 '18 at 19:44


Peter Ruderman
10.1k2352
10.1k2352
asked Nov 19 '18 at 19:34
LehksLehks
578
578
2
Possible duplicate of Does Windows have a __declspec equivalent to Unix GCC's __attribute__((weak))?
– RbMm
Nov 19 '18 at 19:51
1
#pragma comment(linker, "/alternatename:f=__f")
must be (where in place f and __f must be exactly mangled names)
– RbMm
Nov 19 '18 at 19:53
@RbMm: That doesn't look lkke a duplicate.
– R..
Nov 20 '18 at 2:28
@R.. - may be i mistake. however this - stackoverflow.com/a/12397639/6401656 is answer for current question
– RbMm
Nov 20 '18 at 7:19
@RbMm: "same solution works" doesn't imply question is duplicate.
– R..
Nov 20 '18 at 12:30
add a comment |
2
Possible duplicate of Does Windows have a __declspec equivalent to Unix GCC's __attribute__((weak))?
– RbMm
Nov 19 '18 at 19:51
1
#pragma comment(linker, "/alternatename:f=__f")
must be (where in place f and __f must be exactly mangled names)
– RbMm
Nov 19 '18 at 19:53
@RbMm: That doesn't look lkke a duplicate.
– R..
Nov 20 '18 at 2:28
@R.. - may be i mistake. however this - stackoverflow.com/a/12397639/6401656 is answer for current question
– RbMm
Nov 20 '18 at 7:19
@RbMm: "same solution works" doesn't imply question is duplicate.
– R..
Nov 20 '18 at 12:30
2
2
Possible duplicate of Does Windows have a __declspec equivalent to Unix GCC's __attribute__((weak))?
– RbMm
Nov 19 '18 at 19:51
Possible duplicate of Does Windows have a __declspec equivalent to Unix GCC's __attribute__((weak))?
– RbMm
Nov 19 '18 at 19:51
1
1
#pragma comment(linker, "/alternatename:f=__f")
must be (where in place f and __f must be exactly mangled names)– RbMm
Nov 19 '18 at 19:53
#pragma comment(linker, "/alternatename:f=__f")
must be (where in place f and __f must be exactly mangled names)– RbMm
Nov 19 '18 at 19:53
@RbMm: That doesn't look lkke a duplicate.
– R..
Nov 20 '18 at 2:28
@RbMm: That doesn't look lkke a duplicate.
– R..
Nov 20 '18 at 2:28
@R.. - may be i mistake. however this - stackoverflow.com/a/12397639/6401656 is answer for current question
– RbMm
Nov 20 '18 at 7:19
@R.. - may be i mistake. however this - stackoverflow.com/a/12397639/6401656 is answer for current question
– RbMm
Nov 20 '18 at 7:19
@RbMm: "same solution works" doesn't imply question is duplicate.
– R..
Nov 20 '18 at 12:30
@RbMm: "same solution works" doesn't imply question is duplicate.
– R..
Nov 20 '18 at 12:30
add a comment |
1 Answer
1
active
oldest
votes
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.
compile nothing prove here. need link, becausef
if not found redirected to__f
at link time. also#pragma comment(linker, "/alternatename:f=__f")
only for x64 and c code. for c++ code symbols will be mangled?f@@YAXXZ=?__f@@YAXXZ
must be. for c and x86 also will be mangle depend from calin convention. say_f=___f
for __cdecl or_f@0=___f@0
for __stdcall and@f@0=@__f@0
for __fastcall
– RbMm
Nov 20 '18 at 13:06
I tested it on my PC. But I obviously could not link it here. rextester has an older version of VC++ compiler.
– P.W
Nov 20 '18 at 13:07
your current code will be ok only if you compile as c code and target platform x64 otherwise you got unresolved external symbol
– RbMm
Nov 20 '18 at 13:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381461%2fdoes-visual-c-provide-a-language-construct-with-the-same-functionality-as-a%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
compile nothing prove here. need link, becausef
if not found redirected to__f
at link time. also#pragma comment(linker, "/alternatename:f=__f")
only for x64 and c code. for c++ code symbols will be mangled?f@@YAXXZ=?__f@@YAXXZ
must be. for c and x86 also will be mangle depend from calin convention. say_f=___f
for __cdecl or_f@0=___f@0
for __stdcall and@f@0=@__f@0
for __fastcall
– RbMm
Nov 20 '18 at 13:06
I tested it on my PC. But I obviously could not link it here. rextester has an older version of VC++ compiler.
– P.W
Nov 20 '18 at 13:07
your current code will be ok only if you compile as c code and target platform x64 otherwise you got unresolved external symbol
– RbMm
Nov 20 '18 at 13:10
add a comment |
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.
compile nothing prove here. need link, becausef
if not found redirected to__f
at link time. also#pragma comment(linker, "/alternatename:f=__f")
only for x64 and c code. for c++ code symbols will be mangled?f@@YAXXZ=?__f@@YAXXZ
must be. for c and x86 also will be mangle depend from calin convention. say_f=___f
for __cdecl or_f@0=___f@0
for __stdcall and@f@0=@__f@0
for __fastcall
– RbMm
Nov 20 '18 at 13:06
I tested it on my PC. But I obviously could not link it here. rextester has an older version of VC++ compiler.
– P.W
Nov 20 '18 at 13:07
your current code will be ok only if you compile as c code and target platform x64 otherwise you got unresolved external symbol
– RbMm
Nov 20 '18 at 13:10
add a comment |
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.
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.
edited Nov 21 '18 at 7:04
answered Nov 20 '18 at 7:44
P.WP.W
11.7k3842
11.7k3842
compile nothing prove here. need link, becausef
if not found redirected to__f
at link time. also#pragma comment(linker, "/alternatename:f=__f")
only for x64 and c code. for c++ code symbols will be mangled?f@@YAXXZ=?__f@@YAXXZ
must be. for c and x86 also will be mangle depend from calin convention. say_f=___f
for __cdecl or_f@0=___f@0
for __stdcall and@f@0=@__f@0
for __fastcall
– RbMm
Nov 20 '18 at 13:06
I tested it on my PC. But I obviously could not link it here. rextester has an older version of VC++ compiler.
– P.W
Nov 20 '18 at 13:07
your current code will be ok only if you compile as c code and target platform x64 otherwise you got unresolved external symbol
– RbMm
Nov 20 '18 at 13:10
add a comment |
compile nothing prove here. need link, becausef
if not found redirected to__f
at link time. also#pragma comment(linker, "/alternatename:f=__f")
only for x64 and c code. for c++ code symbols will be mangled?f@@YAXXZ=?__f@@YAXXZ
must be. for c and x86 also will be mangle depend from calin convention. say_f=___f
for __cdecl or_f@0=___f@0
for __stdcall and@f@0=@__f@0
for __fastcall
– RbMm
Nov 20 '18 at 13:06
I tested it on my PC. But I obviously could not link it here. rextester has an older version of VC++ compiler.
– P.W
Nov 20 '18 at 13:07
your current code will be ok only if you compile as c code and target platform x64 otherwise you got unresolved external symbol
– RbMm
Nov 20 '18 at 13:10
compile nothing prove here. need link, because
f
if not found redirected to __f
at link time. also #pragma comment(linker, "/alternatename:f=__f")
only for x64 and c code. for c++ code symbols will be mangled ?f@@YAXXZ=?__f@@YAXXZ
must be. for c and x86 also will be mangle depend from calin convention. say _f=___f
for __cdecl or _f@0=___f@0
for __stdcall and @f@0=@__f@0
for __fastcall– RbMm
Nov 20 '18 at 13:06
compile nothing prove here. need link, because
f
if not found redirected to __f
at link time. also #pragma comment(linker, "/alternatename:f=__f")
only for x64 and c code. for c++ code symbols will be mangled ?f@@YAXXZ=?__f@@YAXXZ
must be. for c and x86 also will be mangle depend from calin convention. say _f=___f
for __cdecl or _f@0=___f@0
for __stdcall and @f@0=@__f@0
for __fastcall– RbMm
Nov 20 '18 at 13:06
I tested it on my PC. But I obviously could not link it here. rextester has an older version of VC++ compiler.
– P.W
Nov 20 '18 at 13:07
I tested it on my PC. But I obviously could not link it here. rextester has an older version of VC++ compiler.
– P.W
Nov 20 '18 at 13:07
your current code will be ok only if you compile as c code and target platform x64 otherwise you got unresolved external symbol
– RbMm
Nov 20 '18 at 13:10
your current code will be ok only if you compile as c code and target platform x64 otherwise you got unresolved external symbol
– RbMm
Nov 20 '18 at 13:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381461%2fdoes-visual-c-provide-a-language-construct-with-the-same-functionality-as-a%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Possible duplicate of Does Windows have a __declspec equivalent to Unix GCC's __attribute__((weak))?
– RbMm
Nov 19 '18 at 19:51
1
#pragma comment(linker, "/alternatename:f=__f")
must be (where in place f and __f must be exactly mangled names)– RbMm
Nov 19 '18 at 19:53
@RbMm: That doesn't look lkke a duplicate.
– R..
Nov 20 '18 at 2:28
@R.. - may be i mistake. however this - stackoverflow.com/a/12397639/6401656 is answer for current question
– RbMm
Nov 20 '18 at 7:19
@RbMm: "same solution works" doesn't imply question is duplicate.
– R..
Nov 20 '18 at 12:30