Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7070517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:34:34+00:00 2026-05-28T05:34:34+00:00

For GCC and Clang, I can easily do this: // absolute value inline constexpr

  • 0

For GCC and Clang, I can easily do this:

    // absolute value
    inline constexpr int abs(const int number)
    { return __builtin_abs(number); }
    inline constexpr long abs(const long number)
    { return __builtin_labs(number); }
    inline constexpr long long abs(const long long number)
    { return __builtin_llabs(number); }
    inline constexpr double abs(const double& number)
    { return __builtin_fabs(number); }
    inline constexpr float abs(const float& number)
    { return __builtin_fabsf(number); }
    inline constexpr long double abs(const long double& number)
    { return __builtin_fabsl(number); }

Which works like a charm. I’d like to do a similar thing for pretty much every math function, and have my code work on MSVC as well. How can I do the equivalent of the above for MSVC?

EDIT: for clarity: the question is about the __builtin_* functions, nothing else. I tried

#pragma intrinsic(abs)

but this needs a declaration of the abs function, which I would like not to have in my global namespace.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:34:34+00:00Added an answer on May 28, 2026 at 5:34 am

    Intrinsic functions are not portable, so you’ll have to manually look up the corresponding builtin function and add it to the list, and use #ifdef to switch modes.

    You don’t have to have to have abs in the global namespace, by the way: include <cstdlib> instead of <stdlib.h> and you will get std::abs instead.

    Compilers know what their own intrinsics are, MSVC uses the /Oi switch to enable them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

int bar = 2; if (bar) { int bar; } Neither gcc or Clang
GCC compiles (using gcc --omit-frame-pointer -s ): int the_answer() { return 42; } into
I want to print a double value to std::cout portably (GCC, clang, MSVC++) such
Does anyone have experience with LLVM , llvm-gcc , or Clang ? The whole
GCC 4.4.1, C99 I am using size_t , and size_t is an unsigned int
A pointer to non-const data can be implicitly converted to a pointer to const
Both GCC and Clang do not complain if I assign a string literal to
Setup Given this user-defined type: struct T { static int x; int y; T()
Just compiled clang-2.9 release and it can't link an hello world example. There is
Clang's own diagnostics propaganda contains this exerpt: Since Clang has range highlighting, it never

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.