想看一下VS2010中abs函数的写法

sai_johnny 2013-11-17 09:43:04
谁能帮忙贴一下VS2010中abs()函数的代码?
先行谢过~~
...全文
393 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
sai_johnny 2013-11-18
  • 打赏
  • 举报
回复
引用 8 楼 zhao4zhong1 的回复:
C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\abs.c
/***
*abs.c - find absolute value
*
*       Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
*       defines abs() - find the absolute value of an int.
*
*******************************************************************************/

#include <cruntime.h>
#include <stdlib.h>

#pragma function(abs, _abs64)

int __cdecl abs (
        int number
        )
{
        return( number>=0 ? number : -number );
}
__int64 __cdecl _abs64(
        __int64 num
        )
{
        return (num >=0 ? num : -num);
}
还是赵老师好人啊 即给源码又给路径。真是明白我的难处啊
sai_johnny 2013-11-18
  • 打赏
  • 举报
回复
引用 6 楼 netbooting 的回复:

    return a < 0 ? -a : a;
我最开始也是这样写,然后就想用位运算取反+1会不会更好些。。 因此想看看VS里是怎么写的~~~ 谢谢了
赵4老师 2013-11-18
  • 打赏
  • 举报
回复
C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\abs.c
/***
*abs.c - find absolute value
*
*       Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
*       defines abs() - find the absolute value of an int.
*
*******************************************************************************/

#include <cruntime.h>
#include <stdlib.h>

#pragma function(abs, _abs64)

/***
*int abs(number) - find absolute value of number
*
*Purpose:
*       Returns the absolute value of number (if number >= 0, returns number,
*       else returns -number).
*
*Entry:
*       int number - number to find absolute value of
*
*Exit:
*       returns the aboslute value of number
*
*Exceptions:
*
*******************************************************************************/

int __cdecl abs (
        int number
        )
{
        return( number>=0 ? number : -number );
}
__int64 __cdecl _abs64(
        __int64 num
        )
{
        return (num >=0 ? num : -num);
}
junlinfushi 2013-11-18
  • 打赏
  • 举报
回复
引用 6 楼 netbooting 的回复:

    return a < 0 ? -a : a;
netbooting 2013-11-18
  • 打赏
  • 举报
回复

    return a < 0 ? -a : a;
sai_johnny 2013-11-18
  • 打赏
  • 举报
回复
求好人~\(≧▽≦)/~
sai_johnny 2013-11-17
  • 打赏
  • 举报
回复
引用 3 楼 zhaowech 的回复:
你对源代码抱有什么样的疑问呢?
木有疑问,就想看看它是怎么写的. 学习一下他的写法。
孤影品茗 2013-11-17
  • 打赏
  • 举报
回复
你对源代码抱有什么样的疑问呢?
sai_johnny 2013-11-17
  • 打赏
  • 举报
回复
引用 1 楼 ForestDB 的回复:
abs上点右键,看有无“跳转到定义”这一命令。
嗯嗯。主要是手头没有安装VS,没办法查看函数的内容。 设个断点,然后调试进入到函数内部也是可以看到的。
ForestDB 2013-11-17
  • 打赏
  • 举报
回复
abs上点右键,看有无“跳转到定义”这一命令。

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧