C中的stdin
與STDIN_FILENO
之間的實際區別是什麼?stdin和STDIN_FILENO有什麼區別?
回答
接口。像其他人一樣,stdin
是由標準c庫定義的FILE *
。您可以使用fread
,fwrite
和fprintf
等一些更高級別的接口。另一方面,STDIN_FILENO
只是一個文件描述符(幾乎可以肯定是0)。這通過諸如read
和write
之類的使用略微較低級別的接口。
沒有一個答案提到'STDIN_FILENO'是'
@KeithThompson謝謝,正在尋找這個! – KGCybeX 2016-10-20 17:34:13
stdin
是用於從沒有比標準等中獲得輸入默認文件指針。
STDIN_FILENO
是默認的標準輸入文件描述符數是0
。它基本上是一個通用的定義指令。
從/usr/include/stdio.h
,
/* Standard streams. */
extern struct _IO_FILE *stdin; /* Standard input stream. */
extern struct _IO_FILE *stdout; /* Standard output stream. */
extern struct _IO_FILE *stderr; /* Standard error output stream. */
/* C89/C99 say they're macros. Make them happy. */
#define stdin stdin
#define stdout stdout
#define stderr stderr
從/usr/include/unistd.h
/* Standard file descriptors. */
#define STDIN_FILENO 0 /* Standard input. */
#define STDOUT_FILENO 1 /* Standard output. */
#define STDERR_FILENO 2 /* Standard error output. */
例,stdin
(_IO_FILE
在/usr/include/libio.h
定義)是一個結構的數據。 STDIN_FILENO
是一個宏常量,它指向內核使用的文件描述符。
#include <stdio.h>
#include <unistd.h>
void
stdin_VS_STDIN_FILENO(void)
{
printf("stdin->_flags = %hd\n", stdin->_flags);
printf("STDIN_FILENO : %d\n", STDIN_FILENO);
}
int
main(void)
{
stdin_VS_STDIN_FILENO();
return 0;
}
- 1. Ruby中STDIN和$ stdin有什麼區別?
- 2. STDIN和tty之間有什麼區別?
- 3. python中的stdin和sys.argv有什麼區別?
- 4. 有什麼區別`和$(Bash中有什麼區別?
- 5. 有什麼區別? :和||
- 6. &&和||有什麼區別?
- 7. 「/」和「/ *」有什麼區別?
- 8. 有什麼區別:。!和:r!?
- 9. ==和===有什麼區別?
- 10. Appender和〜有什麼區別?
- 11. $ @和$ *有什麼區別?
- 12. is和=有什麼區別?
- 13. #.00和#。##有什麼區別?
- 14. `==`和`is`有什麼區別?
- 15. '=='和'==='有什麼區別?
- 16. /和/#/有什麼區別?
- 17. | 0和~~有什麼區別?
- 18. `&`和`ref`有什麼區別?
- 19. ==和===有什麼區別?
- 20. ==和===有什麼區別?
- 21. `{}`和`[]`有什麼區別?
- 22. JavaScript和=== ===有什麼區別?
- 23. difftime和' - '有什麼區別?
- 24. =和==有什麼區別?
- 25. xtype和別名有什麼區別?
- 26. Mixpanel:識別()和people.identify()有什麼區別?
- 27. 有什麼區別
- 28. 有什麼區別
- 29. 有什麼區別?
- 30. 有什麼區別?
[關於該主題的有趣討論](http://www.rtems.com/ml/rtems-users/2011/march/msg00101.html)。也許你還應該問爲什麼'fileno(stdin)'與'STDIN_FILENO'不同。 – user7116 2013-02-27 02:50:00
@ user7116您的鏈接已遺失。 – 2014-02-27 06:13:51
此鏈接的作品http://www.rtems.org/ml/rtems-users/2011/march/thrd1.html#00101 – pixelbeat 2014-03-19 01:10:48