Vladimir Because they are new data types, and that''s what `typedef` is therefor. Because it''s convenient to have them as data type for the codethat follows? Immediatelly after the above, a few utility functions are prototyped,all of them using the new types in one way or another, as data types: DIR *opendir(char *dirname);Dirent *readdir(DIR *dfd);void closedir(DIR *dfd); In the code that follows, new types are again heavily used (e.g.dirwalk( ) uses them internally as well). For enhanced readability, andsheer ease of typing, it was worth `typedef`-ing them, IMHO. Cheers Vladimir Vladimir S. Oka写道:Vladimir S. Oka wrote: Chad写道: 在第180页的第2版The C Programming Language中,通过 Kernighan和Richtie,他们使用以下内容: #define NAME_MAX 14 typedef struct { long ino; char name [NAME_MAX + 1]; } Dirent; typedef struct { int fd; Dirent d; } DIR; On page 180 from the 2nd edition of "The C Programming Language" by Kernighan and Richtie, they use the following: #define NAME_MAX 14 typedef struct { long ino; char name[NAME_MAX+1]; } Dirent; typedef struct { int fd; Dirent d; } DIR; What is the reasoning behind typedefing these structures? 因为它们是新的数据类型,那就是`typedef`是什么。因为将它们作为后面的代码的数据类型很方便吗? 在上面的内容之后,一些实用函数就是原型,所有这些函数都使用了以这种或那种方式的新类型,作为数据类型: DIR * opendir(char * dirname); Dirent * readdir(DIR * dfd); void closedir( DIR * dfd); 在下面的代码中,新的类型再次被大量使用(例如, dirwalk()也在内部使用它们)。为了增强可读性,并且简单易于打字,值得`typedef`-ing他们,恕我直言。 干杯 弗拉基米尔 Because they are new data types, and that''s what `typedef` is there for. Because it''s convenient to have them as data type for the code that follows? Immediatelly after the above, a few utility functions are prototyped, all of them using the new types in one way or another, as data types: DIR *opendir(char *dirname); Dirent *readdir(DIR *dfd); void closedir(DIR *dfd); In the code that follows, new types are again heavily used (e.g. dirwalk( ) uses them internally as well). For enhanced readability, and sheer ease of typing, it was worth `typedef`-ing them, IMHO. Cheers Vladimir 我认为我(是吗?)真的画了一个空白是为什么他们不去? 类似于: struct internal_name { int fd; Dirent d; } DIR; 是的,我是这个笨蛋。我需要至少24小时才能沉入其中。 谢谢 Chad I think what I am (was?) really drawing a blank is why don''t they gosomething like: struct internal_name {int fd;Dirent d;} DIR; Yes, I''m this boneheaded. I need at least 24 hours for this to sink in. ThanksChad 这篇关于来自第2版“The C Programming Language”的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-02 12:52