2011年3月31日 星期四

SED: How to remove newline (\n)?

SED: How can I replace a newline (\n)?
http://stackoverflow.com/questions/1251999/sed-how-can-i-replace-a-newline-n

sed ':a;N;$!ba;s/\n/ /g'

This will read the whole file in a loop, then replaces the newline(s) with a space.

1. create a register via :a
2. append the current and next line to the register via N
3. if we are before the last line, branch to the created register $!ba (`$! means not to do it on the last line (as there should be one final newline)).
4. finally the substitution replaces every newline with a space on the pattern space (which is the contents of the a register = the whole file.

2011年3月30日 星期三

BASH: multiple variable substitution


a=1;
x=a;

echo ${$x}

bash: ${$x}: bad substitution

eval y='$'$x;echo $y
1

echo a=$(eval echo '$'$(echo $x))
a=1


a0=000
a1=111
for i in 0 1 ; do echo a$i=$(eval echo '$'$(echo a$i));done
a0=000
a1=111

FC14: make error: mixed implicit and normal rules

Makefile error: mixed implicit and normal rules. Stop.
http://blackfin.uclinux.org/gf/project/uclinux-dist/forum/?_forum_action=ForumMessageBrowse&thread_id=43746&action=ForumBrowse

I recently upgraded to Fedora 14 and included was the upgrade of make from 3.81 to 3.82. The newer version complains when it encounters a line in a Makefile that contains both static and implicit rules

2011年3月24日 星期四

[openssl.org #1546] gcc 4.2 and openssl 0.9.8e - Openssl

[openssl.org #1546] gcc 4.2 and openssl 0.9.8e - Openssl
http://fixunix.com/openssl/156075-openssl-org-1546-gcc-4-2-openssl-0-9-8e.html

uClibc 0.9.31 testsuite - error: dereferencing pointer to incomplete type

While building uClibc 0.9.31 testsuite with buildroot-2010.05, enabling BR2_UCLIBC_INSTALL_TEST_SUITE, I encountered following error:

locale/tst-xlocale2.c

static int
do_test (locale_t l)
{
int result = 0;
size_t n;

#define DO_TEST(TEST, RES) \
for (n = 0; n < sizeof (str) - 1; ++n) \
if ('0' + (TEST (str[n], l) != 0) != RES[n]) \
{ \
printf ("%s(%c) failed\n", #TEST, str[n]); \
result = 1; \
}

DO_TEST (isdigit_l, exd);
DO_TEST (isalpha_l, exa);
DO_TEST (isxdigit_l, exx);

return result;
}


Will result in:
error: dereferencing pointer to incomplete type


change TEST (str[n], l) to TEST (str[n], &l) result in:
error: request for member '__ctype_b' in something not a structure or union



usr/include/ctype.h
# define __isctype_l(c, type, locale) ((locale)->__ctype_b[(int) (c)] & (__ctype_mask_t) type)
# define __isalnum_l(c,l) __isctype_l((c), _ISalnum, (l))
# define __isalpha_l(c,l) __isctype_l((c), _ISalpha, (l))
# define __iscntrl_l(c,l) __isctype_l((c), _IScntrl, (l))
# define __isdigit_l(c,l) __isctype_l((c), _ISdigit, (l))
# define __islower_l(c,l) __isctype_l((c), _ISlower, (l))
# define __isgraph_l(c,l) __isctype_l((c), _ISgraph, (l))
# define __isprint_l(c,l) __isctype_l((c), _ISprint, (l))
# define __ispunct_l(c,l) __isctype_l((c), _ISpunct, (l))
# define __isspace_l(c,l) __isctype_l((c), _ISspace, (l))
# define __isupper_l(c,l) __isctype_l((c), _ISupper, (l))
# define __isxdigit_l(c,l) __isctype_l((c), _ISxdigit, (l))
# define __isblank_l(c,l) __isctype_l((c), _ISblank, (l))

# if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) \
&& defined __UCLIBC_SUSV4_LEGACY__
# define __isascii_l(c,l) ((l), __isascii (c))
# define __toascii_l(c,l) ((l), __toascii (c))
# endif

# define isalnum_l(c,l) __isalnum_l ((c), (l))
# define isalpha_l(c,l) __isalpha_l ((c), (l))
# define iscntrl_l(c,l) __iscntrl_l ((c), (l))
# define isdigit_l(c,l) __isdigit_l ((c), (l))
# define islower_l(c,l) __islower_l ((c), (l))
# define isgraph_l(c,l) __isgraph_l ((c), (l))
# define isprint_l(c,l) __isprint_l ((c), (l))
# define ispunct_l(c,l) __ispunct_l ((c), (l))
# define isspace_l(c,l) __isspace_l ((c), (l))
# define isupper_l(c,l) __isupper_l ((c), (l))
# define isxdigit_l(c,l) __isxdigit_l ((c), (l))
# define isblank_l(c,l) __isblank_l ((c), (l))



Original error message:
/usr/bin/make -j9 -C /buildroot-2010.05/buildroot-2010.05/output/toolchain/uClibc-0.9.31/test \
ARCH_CFLAGS=-I/arm-linux-le-uclibc-gcc-4.3.3-2010.05/usr/include \
UCLIBC_ONLY=1 TEST_INSTALLED_UCLIBC=1 compile -j1

(.....)

make[2]: Entering directory `/buildroot-2010.05/buildroot-2010.05/output/toolchain/uClibc-0.9.31/test/locale'
/arm-linux-le-uclibc-gcc-4.3.3-2010.05/usr/bin/arm-unknown-linux-uclibcgnueabi-gcc -nostdinc -I../../install_dir/usr/include -I../../test -D_GNU_SOURCE -I/buildroot-2010.05/buildroot-2010.05/output/toolchain/linux/include/ -isystem /arm-linux-le-uclibc-gcc-4.3.3-2010.05/usr/lib/gcc/arm-unknown-linux-uclibcgnueabi/4.3.3/include-fixed -isystem /arm-linux-le-uclibc-gcc-4.3.3-2010.05/usr/lib/gcc/arm-unknown-linux-uclibcgnueabi/4.3.3/include -Os -funit-at-a-time -fmerge-all-constants -fno-tree-loop-optimize -fno-tree-dominator-opts -fno-strength-reduce -fstrict-aliasing -funsigned-char -fno-builtin -fno-asm -std=gnu99 -mlittle-endian -mtune=arm1136jf-s -march=armv6 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wstrict-prototypes -D__USE_GNU -fno-builtin -c tst-xlocale2.c -o tst-xlocale2.o
tst-xlocale2.c: In function 'do_test':
tst-xlocale2.c:59: error: dereferencing pointer to incomplete type
tst-xlocale2.c:60: error: dereferencing pointer to incomplete type
tst-xlocale2.c:61: error: dereferencing pointer to incomplete type
make[2]: *** [tst-xlocale2] Error 1
make[2]: Leaving directory `/buildroot-2010.05/buildroot-2010.05/output/toolchain/uClibc-0.9.31/test/locale'
make[1]: *** [_dircompile_locale] Error 2
make[1]: Leaving directory `/buildroot-2010.05/buildroot-2010.05/output/toolchain/uClibc-0.9.31/test'
make: *** [/buildroot-2010.05/buildroot-2010.05/output/toolchain/uClibc-0.9.31/test/unistd/errno] Error 2

2011年3月22日 星期二

Bug in 0.9.31 with __errno_location in linuxthreads.old

Bug in 0.9.31 with __errno_location in linuxthreads.old
http://old.nabble.com/Bug-in-0.9.31-with-__errno_location-in-linuxthreads.old-td28525524.html

Following are the pass cases:
# ./test1
(press control-C to stop running)

# ./test2
thread: Failed to connect (-1 errno=101): Network is unreachable
main: Failed to connect (-1 errno=101): Network is unreachable


Following are the failed cases:

# ./test1
1026: (0/0) got 0 instead of 9
1026: (1/1) got 0 instead of 9
1026: (2/2) got 0 instead of 9
1026: (3/3) got 0 instead of 9
1026: (4/4) got 0 instead of 9
1026: (5/5) got 0 instead of 9
1026: (6/6) got 0 instead of 9
1026: (7/7) got 0 instead of 9
1026: (8/8) got 0 instead of 9
1026: (9/9) got 0 instead of 9


# ./test2
thread: Failed to connect (-1 errno=0): Network is unreachable
main: Failed to connect (-1 errno=101): Network is unreachable

2011年3月20日 星期日

Some build error while building eembc

undefined reference to `__aeabi_uldivmod'

-lgcc
libgcc.a(_divdi3.o):(.ARM.exidx+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
-lgcc_eh


Use
find /toolchain/ -name "*.a" | xargs arm-linux-objdump -x > log

then, find the symbo in log, if found, get which .a contains it.

and note the order of object sources (-l<archive> and .o/.a files), the symbol needed will only be found in following order sources, unless -( is added.
Re: [arm-gnu] GCC library linker problems

http://www.codesourcery.com/archives/arm-gnu/msg01087.html

arm-linux-ld: warning: cannot find entry symbol _start; defaulting to 00008bb0
ld warning cannot find entry symbol _start defaulting to
http://www.linuxforums.org/forum/programming-scripting/154614-ld-warning-cannot-find-entry-symbol-_start-defaulting.html
I googled about this error message and found I would need to pass /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtn.o for runtime support.


Re: cannot find entry symbol _start; defaulting to 01800074
http://www.cygwin.com/ml/crossgcc/2001-04/msg00207.html
Try to compile your "hello" porogram using:
$ powerpc-eabi-gcc -g -mads --verbose -o hello.elf hello.c


At last, all above issue is fixed by using arm-linux-gcc instead of arm-linux-ld.

2011年3月18日 星期五

匯率戰爭(War of Exchange Rate) 筆記

這是一本很好讀的故事書,用很簡單的例子和故事來解釋複雜的觀念;雖然簡單,但是能引起思考。作者是大陸人,因此觀點上較偏向中國,從中國古代的貨幣政策,歐洲人的崛起,金本位制度,到近期的各種金融風暴的起因,並在文末為中國的貨幣政策開脫。但書中也提到,經濟學是一門不準確的學問,就某方面來說,它是一種人類群體交易行為的學問,它解釋過去的事件,並嘗試預測未來的事件。"但我也不確定我就一定正確,因為各學派的認知都還不同"


大衛休莫: 嚴格地說,貨幣並不是用來交易的,而是人們共同約定用以便利商品交換的一種工具,他不是貿易機器上的尺輪,而是一種使齒輪的運轉更加平滑自如的潤滑油

貨幣 基本特性
1. 作為交換媒介使用便利
2. 可以簡單用來衡量價值
3. 可以保值
3. 可以流動

貨幣要有缺稀性,或政府壟斷發行貨幣,人為造成缺稀性

就本質上而言,貨幣是沒有內在價值的,貨幣本身是沒有價值的
一個國家的貨幣,就是用來體現國家財富的工具
任何貨幣背後,支撐它的是信任

任何一種貨幣的價值都包含了兩種因素:能換取的東西的價值,和大家對它的信任程度
匯率就是任兩種貨幣中,換取東西以及信任度這兩個因素的比率
影響匯率的要素 :貿易,投資 和 信心

本國公司出口商品換得的外國貨幣,必須換回本國貨幣才能支付商品成本

貿易順差 出口大於進口
貿易逆差 進口大於出口

貿易順差 -> 貨幣升值,國內商品相對變貴,吸引力降低;國外商品相對變便宜,吸引力提高 -> 進口上升 出口下降 最後趨向均等
貿易逆差 -> 貨幣貶值,國外商品相對變貴,吸引力降低;國內商品相對變便宜,吸引力提高 -> 出口上升 進口下降 最後趨向均等

一個國家 (台、韓、中國) 長期在貿易順差的情況下,又要保持低匯率維持商品競爭力,就必須持有大量的 外匯存底 以抵消貨幣升值力道。外匯存底 可能會拿去買外國國債,或投資外國企業

一個國家 (美國) 長期在貿易逆差的情況下,短期內能拿到價格低廉的產品,但由於國內沒有相對的東西出口,外國持有的本國貨幣會注入本國資本市場 和購買 本國債。

出口 和 進口 是相等的 雙方才可以持續交易
這不是說兩個國家的貿易額都要對等,而是早晚要對等
如果雙方總是有一方賺到,另一方總是虧,那久而久之對方就沒有資產了。如果沒有資產了,那麼其貨幣也就沒價值了,因為誰會對換不了東西的廢紙有信心?

經濟學雖然號稱是科學,又有著諸多複雜的公式,但他與真正的科學有著本質性的不同。
科學能告訴你:什麼樣的條件必定會發生什麼樣的結果。
經濟學只能告訴你:過去發生的事是什麼原因造成的,但我也不確定我就一定正確,因為各學派的認知都還不同。另外,我也無法預測未來,不知道什麼樣的條件一定能造成一種必然的結果。我只能說,未來可能是什麼樣子的。

投資者根據過去歷史與未來預期來判斷,即 信心
大家在做判斷時會觀察別人


貨幣的缺稀性 是 人造的


這本書給我最大的啟示就是:不要過度信任人為的貨幣,人造的缺稀性,就是一種風險。
借錢給國家也是有一定風險的
國家也可以破產,可以不還,或者是印鈔票還
尤其是國家遇到危機需要錢的時候,通常印鈔票是最好的選擇,結果導致 通貨膨脹
但是那些持有該國債券的就倒楣了

目前我的資產配置是採取股債1:1, VT 25%, VWO 25%, IEF 12.5%, TIP 12.5%, BWX 12.5%, WIP 12.5%
以 美元通膨 的預期下來檢視我的資產配置

股票本身就是一種資產,可以抵擋輕微的通貨膨脹。
同時投資於全球股市,雖然是美元計價,但是其實並不只是美元資產,而在美股的部份只有VT的41.62%, 相當於股票的20.81%

但債卷部份有50%在美債上,這部份曝露在通膨的危險中較大
考慮納入 黃金 資產配置部位 為 購買力保值


郎咸平曝光了中國大陸低工資高物價的驚人秘密!
http://www.showgood.tw/node/1032
中國改革開放造成的巨大奇跡之一,就是形成了西方國家高工資低物價,而中國則是低工資高物價的新的經濟現象。由於把中國的低工資和高物價結合在一起,把美國的高工資和低物價結合在一起,這就使中美兩國實際收入之間的差距,要遠遠高於貨幣收入之間的 差距。在實際生活中,美國工人仍然能夠獨自一人養活一家子四、五口人,而中國工人夫妻倆一起沒日沒夜地幹,養活一個孩子都困難,還時常還需要爺爺奶奶來接 濟。

為什麼中美兩國工人貨幣工資之間的差距在縮小,而中國工人供養家庭的能力在下降?甚至下降到了夫妻二人做工養活一個孩子都困難的狀況,這種狀況不僅在中國,即使在世界工業發展史上,也是絕無僅有的罕見現象。

是什麼原因造成了這樣的現實呢,答案十分簡單:中國財政。

無論是美國的低物價,就是中國的高物價,都是中國財政運行的結果。這就是美國政府比中國人還要關心中國改革開放的根本原因。

首先,就美國低物價來說。中國財政補貼一是通過出口退稅的方式按商品發放;二是通過虧損補貼的方式對企業發放。

其次,就中國高物價來說,則是中國實行高額稅收和通貨膨脹的結果。中國稅收占消費品價格的比重竟然高達64%,而商品本身的比重只有36%,中國老百姓每購買100元的商品中就包含有64元的稅收,超過商品本身近1.8倍。如此驚人的高額稅收加到商品價格裏面,自然會造成物價高高在上。

如果災難到此為止也就罷了,可是對於中國老百姓來講,災難還遠遠沒有結束,中國老百姓同時還要承擔因出口商品造成的巨大通貨膨脹的損失。

中國每出口1美元商品,國內就要按照匯率比大約1比7來增發7元人民幣來平衡,目前中國外匯儲備大約2.3萬億美元,國內由此增發的人民幣 超過16萬億元,相當於2008年3.4萬億市場貨幣流通量(M0)的近5倍,這些由出口結匯投放的巨額貨幣,全部以通貨膨脹的方式轉嫁到了老百姓頭上, 造成老百姓手中貨幣的大幅度貶值,物價自然會相應大幅度上漲。

在此我們看到了一個讓中國老百姓欲哭無淚的荒謬現象:中國出口商品越多,賺取外匯越多,老百姓就越倒楣。

如果中國不出口商品,而是用於國內百姓生活,既能夠提高人民生活水準,又不會發生對外財政補貼;或者退一步來說,如果中國出口商品白白送給外國,不收取美元,國內也就不會增發人民幣,貨幣也不會貶值,中國老百姓的損失也會小一些。

可現在卻是,生產的商品出口到了國外,由出口商品換取的美元也借給了國外,而把由此增發的人民幣留在了國內市場上,變成了沒有任何商品做基礎的“純粹廢紙”。

由於這些增發的“純粹廢紙”與現有貨幣一樣流通,必然會造成現有貨幣大幅貶值和物價大幅上漲。結果就是中國老百姓不僅損失掉了出口商品那部分財富,聯手裏的貨幣財富都在遭受貶值損失。

反觀美國情況恰恰與中國相反,美國市場上的貨幣流向了中國,中國的商品流入了美國市場,由於市場上貨幣減少商品增加,必然導致物價下降,美國老百姓手裏的錢便能購買更多商品。

再加上流向中國的美元又通過中國購買美國國債的方式回流到了美國財政部,美國財政部可以用中國的這些錢來增加公共品的供給,能夠進一步起到降低物價的作用,提高美國老百姓貨幣的購買力。

如果是站在中美兩國老百姓的立場上——而不是站在國家立場上——看待這個問題將更加清楚,中國老百姓生產的商品,被美國老百姓用美元買走了,美元被中國政府拿走了;美國老百姓得到了商品,中國政府得到了美元,而中國老百姓唯一得到的,就是手裏現有貨幣的貶值。

結果就是,美國給中國印發美元紙幣,中國給老百姓印發人民幣紙幣;美國用這些紙幣為美國老百姓換來了所需要的各種商品,中國則相反,用這些紙幣從中國老百姓手裏換走了所生產的各種商品。

而形成這個財富魔方中最關鍵的環節,就是貨幣增發和商品增加之間的分離:新增加的商品流向了美國等西方國家,新增發的貨幣卻留在了中國市場上,不斷稀釋著老百姓手裏貨幣的購買力。

這就是美國高工資低物價,而中國低工資高物價的秘密。

2011年3月15日 星期二

building lmbench

Missing llseek
http://lists.busybox.net/pipermail/uclibc/2006-May/036273.html

> >> I've just been trying to build lmbench[1] with uClibc. The build fails
> >> with an undefined reference to "llseek". uClibc doesn't provide this
> >> symbol, and I'm not sure if it should do as it isn't in any header
> >> file. Does anyone have an opinion on whether or not uClibc should
> >> provide this?
> >
> >uClibc provides it under the name lseek64.
>
> That doesn't answer my question. I know how to get at the
> functionality, but lmbench and therefore perhaps others, expect it to
> be called "llseek". Is this a bug?
It's a bug in lmbench. The program should use lseek and the compiler
options (as reported by confstr()) to make sure file offsets are 64bit
or larger. Both lseek64 and llseek are nonstandard and incorrect to
use.


http://blackfin.uclinux.org/gf/project/uclinux-dist/scmsvn/?action=browse&path=%2Ftrunk%2Fuser%2Fblkfin-apps%2Flmbench3%2Fsrc%2Fdisk.c&r1=1516&r2=5279
--- trunk/user/blkfin-apps/lmbench3/src/disk.c 2005/11/16 09:47:07 1516
+++ trunk/user/blkfin-apps/lmbench3/src/disk.c 2007/05/15 04:02:24 5279
@@ -285,12 +285,28 @@

#define BIGSEEK (1<<30)

+#ifdef __linux__
+
+#ifndef __NR__llseek
+#define __NR__llseek 140
+#endif
+
+static loff_t llseek (int fd, loff_t offset, int origin)
+{
+ loff_t result;
+ int retval;
+
+ retval = syscall(__NR__llseek, fd, (unsigned long long) (offset >> 32),
+ ((unsigned long long) offset) & 0xffffffff,
+ &result, origin);
+ return (retval == -1 ? (loff_t) retval : result);
+}
+#endif
+
int
seekto(int fd, uint64 off)
{
#ifdef __linux__
- extern loff_t llseek(int, loff_t, int);
-
if (llseek(fd, (loff_t)off, SEEK_SET) == (loff_t)-1) {
return(-1);
}

http://blackfin.uclinux.org/gf/project/uclinux-dist/scmsvn/?action=browse&path=%2Fbranches%2F2007R1%2Fuser%2Fblkfin-apps%2Flmbench3%2Fsrc%2Fdisk.c&r1=5035&r2=5280

2011年3月14日 星期一

Common C++ compile issues

Cannot open include file: 'iostream.h': No such file or directory".
FIX: Use following instead.

#include <iostream>

`cout' undeclared
FIX: add following line
using namespace std;

error: ‘strcmp’ was not declared in this scope
FIX: Add following line
#include <cstring>



iostream.h problem
http://bytes.com/topic/c/answers/516995-iostream-h-problem

Fixing the strcmp was not declared in this scope error
http://shiroikuma.com/index.php?cmd=%E7%9B%B8%E6%92%B2%E5%A4%96%EF%BC%9AFixing%20the%20strcmp%20was%20not%20declared%20in%20this%20scope%20error&PHPSESSID=d7d1db712ea0fc6751af41d61629edb1

GCC 4.3 related build problems: missing #include
http://www.cyrius.com/journal/2007/05/10#gcc-4.3-include
Functions and defines Header
find, for_each, sort algorithm
isalnum, toupper cctype
INT_MIN, RAND_MAX climits
printf cstdio
atoi, free, rand cstdlib
EXIT_FAILURE cstdlib
strcmp, memcpy cstring
auto_ptr memory
fd_set, mode_t sys/types.h
typeid typeinfo

2011年3月13日 星期日

testsuites

[wiki] Dhrystone
http://en.wikipedia.org/wiki/Dhrystone
dhry-c (sh install)
http://www.netlib.org/benchmark/dhry-c
Rank Ordering
http://www.netlib.org/performance/rank/dhrystone/index

PDS: The Performance Database Server
http://performance.netlib.org/performance/html/dhrystone.intro.html

The Dhrystone C Programs (dhry.shar), and latest table of results (dhry.tbl) are available via
anonymous@ftp.nosc.mil:/pub/aburto (128.49.192.51)
netlib@ornl.gov



[wiki] Whetstone (benchmark)
http://en.wikipedia.org/wiki/Whetstone_%28benchmark%29

[wiki] EEMBC
http://en.wikipedia.org/wiki/EEMBC

EEMBC -- The Embedded Microprocessor Benchmark Consortium
http://www.eembc.org/home.php
http://www.eembc.org/products/

CoreMark
http://www.coremark.org/download/index.php?pg=download


Blitz++ Library
http://sourceforge.net/projects/blitz/files/blitz/

LMbench - Tools for Performance Analysis
http://www.bitmover.com/lmbench/


DejaGnu - GNU Project - Free Software Foundation (FSF)
http://www.gnu.org/software/dejagnu/
DejaGnu - The GNU Testing Framework: Online Manual
http://www.gnu.org/software/dejagnu/manual/
[wiki] DejaGnu
http://en.wikipedia.org/wiki/DejaGnu
based on Expect, which is in turn based on Tcl



GNU Compiler Collection (GCC) Internals: 5.4 Test Suites
http://www.delorie.com/gnu/docs/gcc/gccint_26.html
GNU Compiler Collection (GCC) Internals: 5.4.2 C Language Test Suites
http://www.delorie.com/gnu/docs/gcc/gccint_28.html
GCC Frequently Asked Questions: Testsuite problems
http://gcc.gnu.org/faq.html#testsuite

2011年3月10日 星期四

Running 32-bit binary in 64-bit FC14

/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

Installation /lib/ld-linux.so.2: bad ELF interpreter
http://www.google.com/support/forum/p/earth/thread?tid=01f2c826926c5136&hl=en

yum install glibc.i686
yum install zlib.i686 patch

2011年3月8日 星期二

What You Need to Know About Stock Dividend Dates

What You Need to Know About Stock Dividend Dates
http://news.morningstar.com/articlenet/article.aspx?id=373061&pgid=rss

Declaration Date
This date, also known as the announcement date, is the date on which a company declares it will pay a dividend.

Record Date
Once a company declares that it will pay a dividend, it then sets the date--the record date--by which you must be a shareholder to receive the dividend.

Ex-Dividend Date (usu. record date - 2 for cash dividends, or record date + 1 for share dividends)
To further complicate matters, dividend-paying stocks also have what are called ex-dividend dates--usually two business days before the record date. If you buy or sell shares of stock between the ex-dividend date and the record date, the stock is said to trade without its dividend during that period. In practical terms, that means that the former owner of the stock--and not its new buyer--will receive the dividend if the transaction occurred on or after the ex-dividend date. If you buy a dividend-paying stock before the ex-dividend date, you will receive the upcoming dividend payment. The reverse is also true: If you sell your stock before the ex-dividend date, you give up your right to claim the dividend.

While cash dividends are the most common form of dividend payment, sometimes a company will pay a dividend in additional shares of the company rather than cash. In that case, the ex-dividend date is the first business day after the stock dividend is paid (and is obviously also after the record date). Thus, if you sell your stock before the ex-dividend date and the company has distributed additional shares, you have sold away your right to that stock dividend, too.

Payment Date
The payment date is straightforward: It's the date that dividend checks are mailed or deposited in shareholders' accounts.

2011年3月1日 星期二

你們希望我們聰明還是快樂?

商業週刊1214期 少點虎媽 多點象媽吧!
http://www.businessweekly.com.tw/article.php?id=42628

多年前,有一回我和太太開車載著三名年幼女兒同行去某處,途中一名女兒突然提問:「你們希望我們聰明還是快樂?」