社区
C++ 语言
帖子详情
求New函数源码
oosky2004
2005-08-24 08:18:05
如题,想看看new函数是怎么实现的?
还有比如其他函数:printf()。。。
...全文
314
15
打赏
收藏
求New函数源码
如题,想看看new函数是怎么实现的? 还有比如其他函数:printf()。。。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
15 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
snowbirdfly
2005-08-25
打赏
举报
回复
是啊~
printf()函数有啊~
但是new是运算符,又不是函数,怎么可能函数的代码呢???
边城狂人
2005-08-25
打赏
举报
回复
new 是函数,那就怪了……!
不过 new 可以重载好像是真的。
printf……如果找到源码我也要一份。
oosky2004
2005-08-25
打赏
举报
回复
----------------------------------vfprintf()--------------------太长了,贴不上来。
/* The function itself. */
int
vfprintf (FILE *s, const CHAR_T *format, va_list ap)
{
/* The character used as thousands separator. */
#ifdef COMPILE_WPRINTF
wchar_t thousands_sep = L'\0';
#else
const char *thousands_sep = NULL;
#endif
/* The string describing the size of groups of digits. */
const char *grouping;
/* Place to accumulate the result. */
int done;
/* Current character in format string. */
const UCHAR_T *f;
/* End of leading constant string. */
const UCHAR_T *lead_str_end;
/* Points to next format specifier. */
const UCHAR_T *end_of_spec;
/* Buffer intermediate results. */
CHAR_T work_buffer[1000];
CHAR_T *workstart = NULL;
CHAR_T *workend;
/* State for restartable multibyte character handling functions. */
#ifndef COMPILE_WPRINTF
mbstate_t mbstate;
#endif
/* We have to save the original argument pointer. */
va_list ap_save;
/* Count number of specifiers we already processed. */
int nspecs_done;
/* For the %m format we may need the current `errno' value. */
int save_errno = errno;
/* 1 if format is in read-only memory, -1 if it is in writable memory,
0 if unknown. */
int readonly_format = 0;
/* This table maps a character into a number representing a
class. In each step there is a destination label for each
class. */
static const int jump_table[] =
{
/* ' ' */ 1, 0, 0, /* '#' */ 4,
0, /* '%' */ 14, 0, /* '\''*/ 6,
0, 0, /* '*' */ 7, /* '+' */ 2,
0, /* '-' */ 3, /* '.' */ 9, 0,
/* '0' */ 5, /* '1' */ 8, /* '2' */ 8, /* '3' */ 8,
/* '4' */ 8, /* '5' */ 8, /* '6' */ 8, /* '7' */ 8,
/* '8' */ 8, /* '9' */ 8, 0, 0,
0, 0, 0, 0,
0, /* 'A' */ 26, 0, /* 'C' */ 25,
0, /* 'E' */ 19, /* F */ 19, /* 'G' */ 19,
0, /* 'I' */ 29, 0, 0,
/* 'L' */ 12, 0, 0, 0,
0, 0, 0, /* 'S' */ 21,
0, 0, 0, 0,
/* 'X' */ 18, 0, /* 'Z' */ 13, 0,
0, 0, 0, 0,
0, /* 'a' */ 26, 0, /* 'c' */ 20,
/* 'd' */ 15, /* 'e' */ 19, /* 'f' */ 19, /* 'g' */ 19,
/* 'h' */ 10, /* 'i' */ 15, /* 'j' */ 28, 0,
/* 'l' */ 11, /* 'm' */ 24, /* 'n' */ 23, /* 'o' */ 17,
/* 'p' */ 22, /* 'q' */ 12, 0, /* 's' */ 21,
/* 't' */ 27, /* 'u' */ 16, 0, 0,
/* 'x' */ 18, 0, /* 'z' */ 13
};
#define NOT_IN_JUMP_RANGE(Ch) ((Ch) < L_(' ') || (Ch) > L_('z'))
#define CHAR_CLASS(Ch) (jump_table[(INT_T) (Ch) - L_(' ')])
#if defined HAVE_SUBTRACT_LOCAL_LABELS && defined SHARED
/* 'int' is enough and it saves some space on 64 bit systems. */
# define JUMP_TABLE_TYPE const int
# define JUMP(ChExpr, table) \
do \
{ \
int offset; \
void *__unbounded ptr; \
spec = (ChExpr); \
offset = NOT_IN_JUMP_RANGE (spec) ? REF (form_unknown) \
: table[CHAR_CLASS (spec)]; \
ptr = &&do_form_unknown + offset; \
goto *ptr; \
} \
while (0)
#else
# \
oosky2004
2005-08-25
打赏
举报
回复
只找到printf()
------------------------------printf()--------------------------
#include <stdarg.h>
#include <stdio.h>
#undef printf
/* Write formatted output to stdout from the format string FORMAT. */
/* VARARGS1 */
int
printf (const char *format, ...)
{
va_list arg;
int done;
va_start (arg, format);
done = vfprintf (stdout, format, arg);
va_end (arg);
return done;
}
#undef _IO_printf
/* This is for libg++. */
strong_alias (printf, _IO_printf);
------------------------------------------------------------------
zhouhuahai
2005-08-25
打赏
举报
回复
楼主可以从<<CSDN C/C++电子杂志>>第一期中 老迈所著的<<可变参数>>一节中找到printf的原理.
ningzhiyu
2005-08-25
打赏
举报
回复
还有,
“new是函数吗???!!!面壁10分钟先!”太过激了吧,呵呵
在使用角度new是操作符,在new实现中,new也是用函数实现的吧
ningzhiyu
2005-08-25
打赏
举报
回复
http://directory.fsf.org/libs/c/
下个glibc
stdio-common下有printf等函数实现代码
new的应该在gcc/g++中用
http://directory.fsf.org/devel/compilers/gpp.html
但真还不好找……找着了告诉我一声:)
oosky2004
2005-08-25
打赏
举报
回复
不好意思,说误嘴了。new是运算符!
SeaWave
2005-08-25
打赏
举报
回复
回复人: xxandxx(luck) ( ) 信誉:100 2005-08-25 13:50:00 得分: 0
new 既然是void,为什么还return res呢?new的代码有问题啊
---------------------
谁说net是void的,它是返回void *,返回一个指针。
oosky2004
2005-08-25
打赏
举报
回复
Kenmark
正解。
我啃
2005-08-25
打赏
举报
回复
……,我觉得UNIX中内核用到的PRINTF函数写的不错,VOID的变量不代表没有返回值而是类型为“空”,也就是所有的指针都可以指向它,但是VOID*类型的指针不能用*(因为它没有类型,不知道读取多少内存单元)
xxandxx
2005-08-25
打赏
举报
回复
new 既然是void,为什么还return res呢?new的代码有问题啊
lyclowlevel
2005-08-25
打赏
举报
回复
void *new(size_t size);
basesky
2005-08-25
打赏
举报
回复
new 操作符的源码
void * operator new( unsigned int cb )
{
void *res = _nh_malloc( cb, 1 );
return res;
}
donkey0811
2005-08-24
打赏
举报
回复
new是函数吗???!!!面壁10分钟先!
java
源码
包---java
源码
大量 实例
Java绘制图片火焰效果,源代码相关注释:前景和背景Image对象、Applet和绘制火焰的效果的Image对象、Applet和绘制火焰的效果的Graphics对象、火焰效果的线程、Applet的高度,图片到图片装载器、绘制火焰效果的X坐标...
matlab遗传算法程序(
new
)
遗传算法MATLB程序,里面有遗传算法的选择、交叉、变异
函数
,一些简单的MABTLAB遗传算法例子!
免费下载:C语言难点分析整理.doc
1. C 语言中的指针和内存泄漏 5 2. C语言难点分析整理 10 3. C语言难点 18 ...82. C程序设计常用算法源代码 412 83. C语言有头结点链表的经典实现 419 84. C语言惠通面试题 428 85. C语言常用宏定义 450
深入理解
new
函数
(C++)
请看代码:(来自vs2005) //
new
: //示例代码: int _tmain(int argc, _TCHAR* argv[]) { int *p=NULL; p=
new
int[10]; //单步跟进 } //到达这里: #if !_VC6SP2 || _DLL void *__...
spyder 怎么看
函数
定义_在spyder中查看
函数
源码
的方法
在spyder中查看
函数
源码
的方法发布时间:2020-07-29 09:17:09来源:亿速云阅读:102作者:清晨这篇文章将为大家详细讲解有关在spyder中查看
函数
源码
的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读...
C++ 语言
64,649
社区成员
250,477
社区内容
发帖
与我相关
我的任务
C++ 语言
C++ 语言相关问题讨论,技术干货分享,前沿动态等
复制链接
扫一扫
分享
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
请不要发布与C++技术无关的贴子
请不要发布与技术无关的招聘、广告的帖子
请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下
试试用AI创作助手写篇文章吧
+ 用AI写文章