Wednesday, August 31, 2005

Memory Locations
For curiosity, you might try printing out the locations s1 and s2 in
the different versions by using printf's %p; you would likely see that
malloc, read-only strings, and stack-based arrays are all in distant
parts of memory.

Wednesday, August 24, 2005

Don't foreget when you define a pointer to define what it points to !
struct mystuct * s;
You can't say s->v1 = ... ; as you didn't say s equals what !!
you 've to say first s = new pointer, or s = return of a function ...

Don't forget to deallocate memory of a pointer received from a function return. (you didn't allocate that memory but it was allocated by the function you called)

Note That:
In a function, you have to return an allocated pointer (or edit a pointer passed to it as an argument) and you CANNOT return address of an object, cuz the object is locally defined and will be destroyed at the function termination, so the address will be pointing to garbage.

Also, it is NOT RECOMMENDED to pass solid objects through functions, especially if they are large size objects or structures as it is overhead on the stack

Wednesday, August 10, 2005

Google capacity:

256 characters
32 words

Thursday, August 04, 2005

"warning: passing arg 2 of `signal' from incompatible pointer type"

This warning appears when the signal handler function is not void

Thursday, July 28, 2005

If a program requires a superuser privileges to do some job, "It is always best to give up the extra privilege when it is no longer needed, just in case the program has a latent bug that someone could exploit".
Richard Stevenes, Unix N/W Prog. V1
see line 11 page 666:
setuid(getuid()); /* don't need special permissions any more */
// it drops superuser privileges that was previuosly given to a normal user to be able to create a raw socket

السلطات البريطانية لم توجه أي اتهام للنشار

طب اعتقلوه بناءاً على ايه؟
عشان شوية إشاعات في الجرايد؟
للدرجة دى من الاحتقار وهضم الحقوق تتعامل الدولة مع مواطنيها لإظهار مدى خنوعها للحكومة البريطانية ؟؟!!؟؟

فعلا : فى مصر، المواطن متهم حتى تثبت براءته

Sunday, July 17, 2005

Struct vs. Union

if you defined:
struct s
int i;
char c;

when you define a variable of type s, a memory of size equals to the size of integer + the size of character will be reserved.

In contrasts, when you define:
union u
int i;
char c;

A variable of type u, results in the reservation of memory size of the max of integer and character, and this makes you are able to use the type u as either integer OR character.

struct = AND
unio = OR
Error msg in gcc:
invalid conversion from `void*' to `char*'

This error message appeared to me in a line using malloc()

when, i changed just the file extension form .cpp to .c the error disappeared !

Tuesday, June 21, 2005

to edit vi options : edit this file:
vi ~/.vimrc
colorscheme morning
set nowrap
set smartindent
" set hls!
set ignorecase
To update your object files:
  • if you changed the source file (.cpp) only, run:
    make install
  • if you change header files, run:
    make clobber install {removes all except source files} (or)
    make clean install {removes only .o files}
  • also you can use rm
    rm *.o
see more info at
Introduction to "make"
to show/hide line numbers in vi, type:

: set number (show)
: set number! (hide)
CPPUNIT bug on RedHat 9

Monday, June 20, 2005

to create a thread: you have to pass a name (address) of a function to pthread_create that is:
  • static
  • take void * as argument
  • retuns void *
--> static function must use static member data only because it is a static method that can't be dependent on any instance object of the class, so which data of which object shall it use ?? so it must use static data that is seen by all object
take care of the order of include files, order them according to dependency.. otherwise, you'l get compilation errors