Wednesday, October 10, 2007

[CPP] Conversion from char** to const char** Not Allowed

Source

http://coding.derkeiler.com/Archive/C_CPP/comp.lang.cpp/2004-10/1514.html

Description

If the conversion from char** to const char ** is allowed, then user may write a sequence of assignments which modifies a constant. Following is an exsample from Gianni Mariani posted at coding.derkeiler.com

const char * A[2] = { "A", "B" };
char * B[2];

int main() {
char ** b = B;
const char ** a = b; // illegal
//const char ** a = ( const char ** ) b; // BAD work-around (1)
//const char * const * a = b; // better option (2)
a[0] = A[0]; // illegal if you use (2) ok if you use (1)
b[0][0] = 'X'; // const violation - big probs if you use (1)
}

Monday, October 08, 2007

[Unix] Frequently Used Commands

grep

grep foo file
print the lines containing the pattern foo in file
ls | grep foo
print the lines from STDIN containing the pattern foo
grep -r -e 'PATTERN' ./user *.txt
Find a pattern PATTERN in all txt files, recursively search for all sub directories of directory "./user"

xrdb

xrdb RESOURCE_FILE
Load the resource file for X windows (e.g. xterm). The default resource file is ".Xdefaults"

top

top
Check the computer resource usage.

ln

ln -s
Check the computer resource usage.

find

find . -name "abcd*"
Find a file with "abcd" as part of the filename in current directory or the sub directories