Ugly Code

看到几行令人纠结的代码:

const int size = 1000;  // array of 1000 integers
int array [size];
int n = 0;
// read an integer into the n+1 th element of array
while (cin >> array[n++]);
n--; // it got incremented once too many times 
//下面处理array与n的代码省略

搞不明白这里

while (cin >> array[n++]);
n--; // it got incremented once too many times 

为什么要这样,明明可以这样写的

while (cin >> array[n])n++;

这种代码看的让人蛋疼。

gcc中关于C/C++标准的选项

man gcc里面说到gcc使用指定的标准编译C/C++的选项是:-std=standard,其中standard可以是

c89(传说中的c89)
iso9899:1990
    Support all ISO C90 programs (certain GNU extensions that conflict with ISO C90
    are disabled). Same as -ansi for C code.

iso9899:199409
    ISO C90 as modified in amendment 1.

c99(传说中的c99)
c9x
iso9899:1999
iso9899:199x
    ISO C99.  Note that this standard is not yet fully supported; see
    <http://gcc.gnu.org/gcc-4.2/c99status.html> for more information.  The names c9x
    and iso9899:199x are deprecated.

gnu89
    GNU dialect of ISO C90 (including some C99 features). This is the default for C code.

gnu99
gnu9x
    GNU dialect of ISO C99.  When ISO C99 is fully implemented in GCC, this will
    become the default.  The name gnu9x is deprecated.

c++98
    The 1998 ISO C++ standard plus amendments. Same as -ansi for C++ code.

gnu++98
    GNU dialect of -std=c++98.  This is the default for C++ code.

还有一个选项就是-ansi,上面也说到了。

以上是在gcc4.2.4里面看到的。