Archive for the ‘study’ Category

c/c++ : operator concepts

Wednesday, July 7th, 2004

presedence must be known

http://www.swansontec.com/sopc.htm

http://docs.roxen.com/pike/7.0/tutorial/expressions/operator_tables.xml

n + n + ++n = ??

for + associativity is left to right ie
n + n + ++n = (n + n) + ++n = whatever

in ( a + b ), b is evaluated first
++n + n v/s n + ++n

constants creates all the problem
0 + n + ++n = ??

constants are removed aside and than variables are evaluated.
ie 0 + n + ++n = 0 + ( n + ++n)

* sucks a lot
i * ++i * i++ = ??

unirary operatos are evaluated first, and then for the * expression the variable are used. ie in the above expression. ( left to right associativity and right evaluated first rules holds)
the steps are : (according to my interpretation, and works well for my compiler)
++i
i++
i * i * i

f***ing na!!

c/c++ undefined behaviour

Monday, July 5th, 2004

http://www.swansontec.com/sopc.htm

they call it “side effects”

IMP : order of evaluation for function arguments is unspecified
therefore the below expression is undefined
f(n++, n);

the order is not defined for =, first ++, second ++
*p++ = *q++

“sequence point” comes into picture. A sequence point is any point in a program’s execution wherein all side effects of previous evaluations are complete and no side effects of subsequent evaluations have started. a ; / () / , / && / || etc can be sequence points.

IMP: the commas that separate the arguments in a function call are not comma operators

c/c++/linux :: char *crypt(char *, char *)

Monday, July 5th, 2004

/** \brief
* crypt fucntion
* used to crypt a key, uselful for linux password
*
* linux uses salt for crypting
* a typical linux shadow password looks like (without quotes)
* “$1$ptqYz.X.$Cspm6f.AE7b.pQuM17JOk/”
*
* note the three $’s (dollar signs in the password)
* theese are used to distinguish salt and hash
* $1$ says that a 8 characters long salt follows it
* so in the above password salt is “ptqYz.X.”
*
* so in the crypt function i am providing the above salt prefixed
* with $1$. for crypt function $1$ means that a md5sum will be used
* to crypt the key.
*
* the password “lakshya” with the above salt will produce the above
* crypted password
*
* md5sum is 22 characters long
*/

#define _XOPEN_SOURCE
#include

int main(int argc, char **argv)
{
printf(”<%s>\n”,crypt(”lakshya”,”$1$ptqYz.X.”));
return 0;
}

c quine

Wednesday, June 23rd, 2004

main(a){a=&quot;main(a){a=%c%s%c;printf(a,34,a,34);}&quot;;printf(a,34,a,34);}

I didnot know the problem i tried to solve so hard had one line solution. “without success” sad

yes this code will print itself. i was really shocked to see the output of the code. i would had never guessd that it will write its own code.

i did some research, in understanding the code. here it is -

main(a){ 

a="main(a){a=%c%s%c;printf(a,34,a,34);}"; 

printf(a,34,a,34); //printf( "main(a){a=%c%s%c;printf(a,34,a,34);}" , 34, a , 34); 

/* both of above commands are equivalent * the format string in printf is issued as a variable * (i didnot know that format string can be a variable) - * * _________--------- the format string --------____%c__%s_%c_ * printf( "main(a){a=%c%s%c;printf(a,34,a,34);}" , 34, a, 34); * * 34 when printed using %c prints " (quote) * * really magical winking * us winking */ 

}

nightout at serverroom. worked on opencv after so many days. i am feeling good about that. i am really afraid that jpn wont give me msbr. i didnot meet him for last 2 weeks. i will work hard now. promise.

aslo i didnot call her, after a promise. she will screw me for sure. i dont have any choice, except lieying to her. but need something really solid. i was admitted in hospital…. not good…. how about a friend getting seroius, and admitted to hospital, and had no time to, even didnot eat. why not jayaram, am i lying.