2007-04-29

Char's pointer's pointer

This is a good example to know how to pass char's pointer to the function.

char *name[3];
name[0] = "a2n";
name[1] = "c9s";
name[2] = "ccn";

Known name at 0x1, and its content is:

{0x100, 0x101, 0x102}

Meaning indicates to "a2n", "c9s" and "ccn", respectively.


The array "name" saves the three string's address in its array space, hence, pass the array "name" to other function might via the address, and access the content of array "name" via address again. In the other word, I shall using "Pointer into Pointer" in the parameters field of array "name". :-)



Example:



void show(char **name)
{
for (int i = 0; i < 3; i++) cout << *name[i] << endl;
}

char *name[3];
name[0] = "a2n";
name[1] = "c9s";
name[2] = "ccn";
show(name);

2007-04-11

How can I create a program alias?

How can I create a program alias?

A. It is possible to create an alias for a program, for example to define johnword.exe to actually run winword.exe. To do this perform the following:

    *Start the registry editor (regedit.exe)
    *Move to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
    *From the Edit menu select New - Key
    *Enter the name of the alias, e.g. johnword.exe and press Enter
    *Move to the new key and double click on the (Default) value (it is blank by default)
    *Set to the fully qualified file name it should run, e.g. C:\Program *Files\Microsoft Office\Office\winword.exe. Click OK
    *Optionally you can create a new String called Path which is where the program will first start running (Edit - New - String Value - Path, double click and set to the starting path)
    *Close the registry editor

If you now select Run from the start menu and type johnword.exe it would start Microsoft Word, cool!

If you type your alias from the command prompt it will not find it, however if you type

C:\> start

it will work fine.

The actual program name does not have to be an .exe program -- it can be any file that has an association (such as "C:\temp\ntfaq.url"). The alias itself can remain as an .exe.

If the alias is an .exe, then the "run" or "start" command does not need to include the extension. If the alias is NOT an .exe, then you need to use the full name but then you are not limited to any extensions (but it must have some extension). Your alias can be John.Savill which you have aliased to "C:\ProgramYadaYadaYada\Winword.exe" and Word will start up just fine.

2007-03-30

Pointer Discrepancy between vc++ & g++


1 #include
2
3 using namespace std;
4
5 int main()
6 {
7 int a = 1, b = 2;
8 int *x;
9
10 cout << "x: " << x << '\t';
11 cout << "*x: " << *x << '\t';
12 cout << "&x: " << &x << '\t';
13
14 cout << endl;
15
16 x = &a;
17 cout << "x = &a" << '\t';
18 cout << "x: " << x << '\t';
19 cout << "*x: " << *x << '\t';
20 cout << "&x: " << &x << '\t';
21
22 cout << endl;
23
24 x = &a - 1;
25 cout << "x = &b" << '\t';
26 cout << "x: " << x << '\t';
27 cout << "*x: " << *x << '\t';
28 cout << "&x: " << &x << '\t';
29
30 cout << endl;
31 return 0;
32 }


Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 (VC6++)


modified code...

x = &a x: 0012FF7C *x: 1 &x: 0012FF74
x = &a-1 x: 0012FF78 *x: 2 &x: 0012FF74


g++ (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)


x: 0xb7f518dc *x: -1 &x: 0xbf97f214
x = &a x: 0xbf97f218 *x: 1 &x: 0xbf97f214
x = &a-1 x: 0xbf97f214 *x: -1080561132 &x: 0xbf97f214



g++ 讓我驚訝!! 結果 VC++ 2005 Expression 也讓我受精。 XD

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86



x = &a x: 0012FF60 *x: 1 &x: 0012FF48
x = &a-1 x: 0012FF5C *x: -858993460 &x: 0012FF48

Pointer sequence #2


1 #include
2
3 using namespace std;
4
5 int main()
6 {
7 int a = 1, b = 2;
8 int *x;
9
10 cout << "x: " << x << '\t';
11 cout << "*x: " << *x << '\t';
12 cout << "&x: " << &x << '\t';
13
14 cout << endl;
15
16 x = &a;
17 cout << "x = &a" << '\t';
18 cout << "x: " << x << '\t';
19 cout << "*x: " << *x << '\t';
20 cout << "&x: " << &x << '\t';
21
22 cout << endl;
23
24 x = &b;
25 cout << "x = &b" << '\t';
26 cout << "x: " << x << '\t';
27 cout << "*x: " << *x << '\t';
28 cout << "&x: " << &x << '\t';
29
30 cout << endl;
31 return 0;
32 }



g++ (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)


x: 0xb7f078dc *x: -1 &x: 0xbff350c4
x = &a x: 0xbff350cc *x: 1 &x: 0xbff350c4
x = &b x: 0xbff350c8 *x: 2 &x: 0xbff350c4




Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 (VC6++)


跑到 line 10 就結束!

then modified code.
x = &a x: 0012FF7C *x: 1 &x: 0012FF74
x = &b x: 0012FF78 *x: 2 &x: 0012FF74

Pointer sequence #1


#include

using namespace std;

int main()
{
int a, b, c, d, e;
int i;

cout << "Input five numbers: \n";
cin >> a >> b >> c >> d >> e;
cout << "A: " << &a << "\nB: " << &b
<< "\nC: " << &c << "\nD: " << &d << "\nE: " << &e;

cout << endl;
return 0;
}



Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 (VC6++)


1
2
3
4
5
A: 0012FF7C
B: 0012FF78
C: 0012FF74
D: 0012FF70
E: 0012FF6C


g++ (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)


1
2
3
4
5
A: 0xbfdc2cec
B: 0xbfdc2ce8
C: 0xbfdc2ce4
D: 0xbfdc2ce0
E: 0xbfdc2cdc




#include

using namespace std;

int main()
{

cout << "Input five numbers: \n";
cin >> a >> b >> c >> d >> e;
for (i = 0; i < 5; i++)
cout << "Var" << i << ":\t"
<< &a - i << " : "
<< *(&a - i) << '\n';

cout << endl;
return 0;
}


Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 (VC6++)


1
2
3
4
5
Var0: 0012FF7C : 1
Var1: 0012FF78 : 2
Var2: 0012FF74 : 3
Var3: 0012FF70 : 4
Var4: 0012FF6C : 5


g++ (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)


1
2
3
4
5
Var0: 0xbfdea9e0 : 1
Var1: 0xbfdea9dc : 2
Var2: 0xbfdea9d8 : 3
Var3: 0xbfdea9d4 : 4
Var4: 0xbfdea9d0 : 5

2007-03-08

All mail -> Gmail

看到 Yi-Feng Tzeng’s Blog 的 用 Gmail 收取外部郵件後,開始動手設定我的幾個信箱都納入 Gmail 管理。

兩個學術單位信箱,Y! 需要付費才有 POP3 收信功能,加上最近的 spam 都直接進入 inbox,所以想要放棄 Y! 了,目前它的功能只剩下 tw.clubs 和網拍的認證而已。

Gmail 方便至極,不用我多說。哈哈,但是我還是覺得有些改進的空間,找個時間去寫 feedback 給他們。

2007-02-18

MITOCW grabber

NAME
    grabber.sh - Grabbing the MIT OCW course data.

SYNOPSIS
    sh grabber.sh

DESCRIPTION
    今天清晨睡不著起來寫的一支小程式,專門用來抓 MIT OCW 的課程資料。獲益就是複習和增進 Regular Expression 的用法,並且搭配很多 Unix pipe (|),小小的心得而已,跟大家分享我的程式。

KNOWN BUGS

    1. Welcome.htm 拉到 index.htm 有瑕疵
    2. URL.txt 裡面有重複的列,因為課程名稱一樣

AUTHOR
    Alan Lu. (alan0098/a/gmail/d/com)




有行數程式碼放在 http://163.26.225.215/~a2n/src/grabber_nu.sh.txt
無行數的程式碼放在 http://163.26.225.215/~a2n/src/grabber.sh.txt


RegExp 小記:

2007-01-13

Remote backup

SSH:
dd if=/dev/foo | ssh foo@foo dd of=foo


FTP:
ftp foo
ftp> bin
ftp> put "| dd if=/dev/foo" foo
ftp> get foo "| dd of=/dev/foo"
ftp> get foo.tar.bz2 "| tar -xj -"


ref: 1. http://www.wsp.krakow.pl/~bar/DOC/ssh_backup.html
2. http://0rz.net/741kp
http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?
topic=/com.ibm.aix.doc/infocenter/howto/HT_prftungd_slowTSMbkupperf.htm
google: backup dd if= ftp -ssh

2007-01-11

GNU GLOBAL

GNU GLOBAL is a source code tag system that works the same way across diverse environments.


17:02:46 :: linux-2.6.19.1 $ time gtags

real 25m56.492s
user 1m44.167s
sys 1m47.283s

17:28:48 :: linux-2.6.19.1 $ time htags

real 43m1.615s
user 3m19.044s
sys 21m41.105s

19:09:04 :: linux-2.6.19.1 $ du -sh HTML/
2.1G HTML/


目前轉好兩個專案,分別是 7-zip 和 FileZilla,放在 野人 。提供這種原始碼線上瀏覽的網站,有大名鼎鼎的 Cross-Referencing Linux ,使用 LXR 系統轉換的。

Update: Notepad++ 399 已新增。

2007-01-05

PCman alasing

PCMan for win32 的版本,針對英文與中文文章時,中文的 refresh 速度比英文慢,難道是 TryeType 的問題嗎?

2006-12-25

libc6-dev

stdio.h is in libc-dev package.

GNU C Library: Development Libraries and Header Files

2006-12-18

youtube-dl

youtube-dl is a small command-line program to download videos from YouTube.com. It requires the Python interpreter, version 2.4 or later, and it's not platform specific. It should work in your Unix box, in Windows or in Mac OS X. The latest version is 2006.12.07. It's licensed under the MIT License, which means you can modify it, redistribute it or use it however you like complying with a few simple conditions.

http://www.arrakis.es/~rggi3/youtube-dl/

2006-12-08

agup daily

I've been execute "apup" to "sodu apt-get upgrade" daily, it's more than edgy distribution, so it's a experiment one. I am afraid of that there're many holes in my box, that if I haven't update one.

2006-11-24

Bootcfg

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/bootcfg.mspx?mfr=true

Boot.ini Boot Parameter Reference

http://msdn2.microsoft.com/en-us/library/ms791480.aspx

Info: /cygdrive/c/EmbestIDE/Build/xgcc-arm-elf/bin/arm-elf-ld: cannot find -lc

是 FAQ

Please set the searching path of c library and gcc library correctly. Select the menu Project> Settings, open project configuration box, select the linked page and the option to add library searching path in drop-down box:
..\..\..\build\xgcc-arm-elf\arm-elf\lib\arm-inter
..\..\..\build\xgcc-arm-elf\lib\gcc-lib\arm-elf\3.0.2\arm-inter

The above path is the relative path of Embest IDE, users can also set absolute path.

2006-11-20

jmsort2.c


#include
//#include "algo.h"

void msort2(int lo, int hi, int S[]);
void mg2(int lo, int mid, int hi, int S[]);


void msort2(int lo, int hi, int S[])
{
int mid;
if ((lo < hi) && ((hi - lo) > 1))
{
mid = (lo + hi) / 2;
//printf(".S[%d]: %d, S[%d]: %d\n", lo, S[lo], mid, S[mid]);
msort2(lo, mid, S);
//printf("..S[%d]: %d, S[%d]: %d\n", mid + 1, S[mid + 1], hi, S[ hi]);
msort2(mid + 1, hi, S);
// Upper is OK
printf("\nlo: %d, mid: %d, hi: %d\n", lo, mid, hi);
mg2(lo, mid, hi, S);
}
}


void mg2(int lo, int mid, int hi, int S[])
{
int i = lo;
int j = mid + 1;
int k = lo;
int U[16];

while ((i <= mid) && (j <= hi))
{
if (S[i] < S[j]) U[k] = S[i++];
else U[k] = S[j++];
k++;
}

int a;
if (i < mid)
for (a = i; a <= mid; a++)
U[a+k] = S[i+a];
else
for (a = j; a <= hi; a++)
U[k+a] = S[j+a];

for (a = lo; a <= hi; a++)
{
S[a] = U[a];
printf("S[%d]: %d, ", a, S[a]);
}
printf("\n");
}


int main(void)
{
int S[] = { 27, 10, 12, 20, 25, 13, 15, 22 };
int sz = sizeof(S) / 4;
int lo = 0;
int hi = sz - 1;

msort2(lo, hi, S);


printf("\nFinally: ");
int a;
for (a = 0; a < 8; a++)
printf("%d, ", S[a]);
printf("\n");

return 0;
}