找回密码
 欢迎注册
楼主: wayne

[提问] volatile 可以用来修饰函数返回值吗

[复制链接]
 楼主| 发表于 2011-5-11 10:15:33 | 显示全部楼层
9# gxqcn 搜了一下, 修饰函数表示 no return: http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
noreturn A few standard library functions, such as abort and exit, cannot return. GCC knows this automatically. Some programs define their own functions that never return. You can declare them noreturn to tell the compiler this fact. For example, void fatal () __attribute__ ((noreturn)); void fatal (/* ... */) { /* ... */ /* Print error message. */ /* ... */ exit (1); } The noreturn keyword tells the compiler to assume that fatal cannot return. It can then optimize without regard to what would happen if fatal ever did return. This makes slightly better code. More importantly, it helps avoid spurious warnings of uninitialized variables. The noreturn keyword does not affect the exceptional path when that applies: a noreturn-marked function may still return to the caller by throwing an exception or calling longjmp. Do not assume that registers saved by the calling function are restored before calling the noreturn function. It does not make sense for a noreturn function to have a return type other than void. The attribute noreturn is not implemented in GCC versions earlier than 2.5. An alternative way to declare that a function does not return, which works in the current version and in some older versions, is as follows: typedef void voidfn (); volatile voidfn fatal; This approach does not work in GNU C++.
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2011-5-11 10:46:04 | 显示全部楼层
7# gxqcn 很好搜索吧: 下载地址: http://www.oldlinux.org/Linux.old/bochs/linux-0.11-040305.zip 源自:http://www.oldlinux.org/ wayne 发表于 2011-5-11 10:12
下载了那个zip档,解压后未发现memory.c文件。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2011-5-11 11:18:05 | 显示全部楼层
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2011-5-11 11:23:43 | 显示全部楼层
13# wayne 顺着这个路径的上级目录,我找到了linux 1.00 的源代码: http://www.oldlinux.org/Linux.old/kernel/1.00/ 发现memory.c 文件里的oom函数 变成了:
  1. void oom(struct task_struct * task)
  2. {
  3. printk("\nout of memory\n");
  4. task->sigaction[SIGKILL-1].sa_handler = NULL;
  5. task->blocked &= ~(1<<(SIGKILL-1));
  6. send_sig(SIGKILL,task,1);
  7. }
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2011-5-11 11:46:37 | 显示全部楼层
这里的 old linux 是指老版本吗? 那最新版的 memory.c 是啥样?能发上来吗?
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2011-5-11 12:03:30 | 显示全部楼层
15# gxqcn 发现oom函数在最新版本的linux里 不见踪迹了 http://git.kernel.org/?p=linux/k ... 984c490c827;hb=HEAD Cache Last Updated: Wed May 11 04:01:52 2011 GMT
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-11-23 16:22 , Processed in 0.027062 second(s), 14 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表