Code Reading

0 why

The purpose of this blog is to write down some useful tips in coding. 

1 starting point of code:

  • c/c++: main
  • java: static void main
  • Microsoft windows: WinMain
  • Java applet or servlet hosts: init

2 logic expression:

this tip can make the if condition more concise

  • && / and: only evaluate the righthand side when the lefthand side is evaluated as "true".
  • || / false: only evaluate the righthand side when the lefthand side is evaluated as "false".
    • eg: fragment from ECHO
      1 if (*++argv && !strcmp(*argv, "-n")){
      2     ...
      3 }
      ECHO
  • assignment expression(赋值表达式) in a logic express
    • int c = 0;
    • while ((c = getopt (argc, argv, "t: "))  != -1)   // first execute assignment expression, and compare the lefthand variable with "-1"(a possible return value of getopt, which means the end of parsing in getopt.)

3 static

  • a function is declared as static while the variables are not, means that the function is visible only within this file, while the variables are potentially visible to all files comprising the program.
  • variables needed only in a single file should be declared as static.

猜你喜欢

转载自www.cnblogs.com/ghjnwk/p/13366197.html