不矫情地编程

Achilles's picture

初学者和很有“思想”的人,都喜欢读代码和背代码,而不是执行和调试代码。他们很喜欢给你一段代码,如:

struct people {
        char name[20];
        int age;
};

struct people *p1[20];
struct people (*p2)[20];
struct people *(p3[20]);

然后问你:哪个是数组的指针?哪个是指针的数组?

这些很混乱的概念,即便一时搞清楚了,日子一长,也很容易记错。除非你整天不干别的,光是卖弄这些东西。不过指针的数组,在实际编程当中还是比较常用的。开源社区和GNU通常采用一种不易混淆的解决办法:

struct people {
        char name[20];
        int age;
};

typedef struct people *p_people;

p_people peoples[20];

这一种很清晰的方法,并且避免了矫情。

Comments

测试capcha

测试capcha

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <font>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.