int main( void ) { int x = ( x = 10, x += x, x ); printf("x=%d\n", x); return 0; }
2010年12月17日 星期五
Tricky initialization of a declaration in C
2010年6月10日 星期四
Linux 下的源程序查看工具
http://www.linuxsir.org/bbs/showthread.php?t=237551
我用下来的感觉是(在debian sid中)
(g)vim + ctags + taglist + cscope + cppcomplete + global
大型程序一定要global的参与,它的分析比较全面。
taglist 精干,需要ctags的支撑 ,直接可以在左边列出函数列表,全局参数列表。(可以排序)
cscope 比较强大,可以对函数以及部分类型定义进行跳转,但有些BUG,好像在某些条件下无法正确找到分析枚举的定义。
cppcomplete 需要ctags的支撑,可以补全类型或者函数名(可不是普通Ctrl+P/N的那种)
global 新版本可以嵌入vim使用,提供比较完整解析和类型索引,和cscope比,稍微差些的就是对类型引用的打印列表中没有标识这个引用在什么函数中进行的。
这些都在我平常的使用中,部分功能还在摸索中。
2010年5月20日 星期四
Java Anonymous Instance
對話框通常只會出現一下下, 用來提示使用者採取某些行動. 當使用者做完決定後, 這個對話框就會消失.
使用匿名類別顯示一個對話框, 亦即建立一個匿名的實體. 當運行完這個對話框後, 系統會自行回收這個匿名實體所佔用的記憶體空間, 從而讓程式在運行中不會佔到不必要的記憶體空間.
使用匿名類別顯示一個對話框, 亦即建立一個匿名的實體. 當運行完這個對話框後, 系統會自行回收這個匿名實體所佔用的記憶體空間, 從而讓程式在運行中不會佔到不必要的記憶體空間.
Java Nested Classes: this
http://mindprod.com/jgloss/this.html
"this" means the current object, the instance we are currently running a method on.
Beware, inside an (anonymous) inner class, "this" refers to the inner class, not the usual enclosing one. If the outer class were called MyOuter, you could get at its this with "MyOuter.this".
Example:
"this" means the current object, the instance we are currently running a method on.
Beware, inside an (anonymous) inner class, "this" refers to the inner class, not the usual enclosing one. If the outer class were called MyOuter, you could get at its this with "MyOuter.this".
Example:
public class MyClass { private String outerClassField = "some value"; public void outerClassMethod() { someObject.addMyListener(new MyListener() { public void processEvent(MyEvent e) { MyClass.this.outherClassField; } }); } }
2010年4月23日 星期五
useful command
- $ find ../../../../MMI/UI_ESIM/porting/PL_Java -iname "*.c" -exec basename "{}" \; | sed -e 's/\.c/\.o/g' | xargs -r rm
- $ find . -iname "iextutil.o" -o -iname "iamsengine.o" -o -iname "kjava_sys_ext.o" | xargs -r rm
- $ svn status | grep -v '?' | cut -b 2- | sed -e 's,\\,/,g' | xargs -r cp --parents -t ../patch_0427_release_merge/
- $ find . -maxdepth 1 ! -iname "pl_java*" | xargs -r rm -rf
- $ find . -maxdepth 1 ! -iname "build*" -a ! -name '.' | xargs -r rm -rf
- $ diff -u -r --ignore-matching-lines=".*\$Id.*" parts_simon/ parts_ting/ | tee diff4.patch
- $ svn diff -c 80580 --diff-cmd diff -x '-u -w -B -t --tabsize=4' > svg_update_hi_diff.log
2010年4月20日 星期二
svn command
generate svn diff (unified) file:
apply diff file:
copy local modified files
retrieve modified files in a commit:
show the latest n svn commit log:
- svn diff -r PREV:COMMITTED $SVN_LINK > svn.patch
- svn diff -c $REVISION_NUMBER $SVN_LINK > svn.patch
- $ svn diff -c 80580 --diff-cmd diff -x '-u -w -B -t --tabsize=4' > svg_update_hi_diff.log
apply diff file:
- patch --verbose --dry-run -p0 < svn.patch
copy local modified files
- svn status | grep -v '?' | cut -b 2- | sed -e 's,\\,/,g' | xargs -r cp --parents -t ../patch_0427_release_merge/
retrieve modified files in a commit:
- svn update -r PREV
- svn update -r HEAD | sed 's,\\,/,g' | cut -b 2- | xargs -r cp --parents -t $DEST
show the latest n svn commit log:
- svn log -l n -v
Nested Classes
Why Use Nested Classes?
There are several compelling reasons for using nested classes, among them:
Java Gossip: 內部類別(Inner class)
So what are inner classes good for anyway?
The advantages of inner classes can be divided into three categories:
There are several compelling reasons for using nested classes, among them:
- It is a way of logically grouping classes that are only used in one place.
- It increases encapsulation.
- Nested classes can lead to more readable and maintainable code.
Java Gossip: 內部類別(Inner class)
- 使用內部類別的好處在於可以直接存取外部類別的私用(private)成員,舉個例子來說,在視窗程式中,您可以使用內部類別來實作一個事件傾聽者類別,這個視窗傾聽者類別可以直接存取視窗元件,而不用透過參數傳遞。
- 另一個好處是,當某個Slave類別完全只服務於一個Master類別時,我們可以將之設定為內部類別,如此使用Master類別的人就不用知道 Slave的存在。
So what are inner classes good for anyway?
The advantages of inner classes can be divided into three categories:
- an object-oriented advantage,
- an organizational advantage, and
- a call-back advantage.
2010年4月14日 星期三
Calling Overridden Methods
While learning Java about overriding methods, I suddenly thought that was it possible to invoke a method, which has been overridden by subclass, of the base class?
After googling it, I found Marco had the same question:
As discussed in this thread[1], "It is Beta's decision whether it wants to use Alpha's foo() or its own, not the calling code's. Allowing code outside the Beta class to influence the binding of its methods breaks the concepts of polymorphism and encapsulation."
After googling it, I found Marco had the same question:
public class MainProgram { public static void main(String[] args) { Beta b = new Beta(); // I want to invoke Alpha.foo() but // on the Beta instance. // I want to cancel the dynamic binding that // makes Beta.foo() get called instead // b.super.foo() <--- obviously doesn't compile } } class Alpha { public void foo() { System.out.println("inside Alpha.foo()"); } } class Beta extends Alpha { public void foo() { System.out.println("inside Beta.foo()"); } }
As discussed in this thread[1], "It is Beta's decision whether it wants to use Alpha's foo() or its own, not the calling code's. Allowing code outside the Beta class to influence the binding of its methods breaks the concepts of polymorphism and encapsulation."
In another discussion thread[2], "You can't call the super method in other objects - that would violate encapsulation. The whole point is that the object controls what its overridden methods do."
That is, there is no way to call an overridden method directly in Java.
2010年4月6日 星期二
Evaluation Order
Evaluation Order
The Java programming language guarantees that the operands of operators appear to be evaluated in a specific evaluation order, namely, from left to right.
It is recommended that code not rely crucially on this specification. Code is usually clearer when each expression contains at most one side effect, as its outermost operation, and when code does not depend on exactly which exception arises as a consequence of the left-to-right evaluation of expressions.
The Java programming language guarantees that the operands of operators appear to be evaluated in a specific evaluation order, namely, from left to right.
It is recommended that code not rely crucially on this specification. Code is usually clearer when each expression contains at most one side effect, as its outermost operation, and when code does not depend on exactly which exception arises as a consequence of the left-to-right evaluation of expressions.
/** * expression evaluation order test */ public class EvaluationOrder { public static void main(String [] args) { int i = 2; int j = i * (i=3); System.out.println(j); } } /* $ java EvaluationOrder 6 */
/* * expression evaluation order test */ int main( void ) { int i = 2; int j = i * (i=3); printf("%d\n", j); } /* gcc (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) $ ./EvaluationOrder.exe 9 */
2010年4月2日 星期五
Operator associativity
http://en.wikipedia.org/wiki/Operator_associativity
In programming languages and mathematical notation, the associativity (or fixity) of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses. Operators may be left-associative, right-associative or non-associative. The associativity and precedence of an operator depends on the programming language in question.
Consider the expression a ~ b ~ c. If the operator ~ has left associativity, this expression would be interpreted as (a ~ b) ~ c and evaluated left-to-right. If the operator has right associativity, the expression would be interpreted as a ~ (b ~ c) and evaluated right-to-left. If the operator is non-associative, the expression might be a syntax error, or it might have some special meaning.
Many programming language manuals provide a table of operator precedence and associativity; see, for example, the table for C and C++.
In programming languages and mathematical notation, the associativity (or fixity) of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses. Operators may be left-associative, right-associative or non-associative. The associativity and precedence of an operator depends on the programming language in question.
Consider the expression a ~ b ~ c. If the operator ~ has left associativity, this expression would be interpreted as (a ~ b) ~ c and evaluated left-to-right. If the operator has right associativity, the expression would be interpreted as a ~ (b ~ c) and evaluated right-to-left. If the operator is non-associative, the expression might be a syntax error, or it might have some special meaning.
Many programming language manuals provide a table of operator precedence and associativity; see, for example, the table for C and C++.
訂閱:
文章 (Atom)