No, but I've done it. I know Rob Pike does it because that's where I learned it from, and everybody knows that Rob Pike does every thing THE RIGHT WAYTM.
#define RANDUM_STRING "HAX MY ANUS"
static unsigned int randum = 0;
/* Algorithm: HAXMYANUS RANDUMB
* Guaranteed to produce random numbers each time */
int rand(){
int randum_num = rand_(strlen(RANDUM_STRING) % randum,randum);
randum *= (randum+randum_num)*5
return randum_num;
}
int rand_(int depth,int a){
if(depth == 0) a;
rand_(depth-1,(int)((a*a+depth)/2)
}
>>12
#define RANDUM_STRING "HAX MY ANUS"
static unsigned int randum = 10;
/* Algorithm: HAXMYANUS RANDUMB
* Guaranteed to produce random numbers each time */
int rand(){
int randum_num = rand_(strlen(RANDUM_STRING) % randum,randum);
randum *= (randum+randum_num)*5
return randum_num;
}
int rand_(int depth,int a){
if(depth == 0) a;
rand_(depth-1,(int)((a*a+depth)/2)
}
>>22
Failing to write to STDOUT is the only reason why printf with a single string argument would return a value less than the length of the string. puts would return a negative value in this case. So, here's how to make it really equivalent: #define hax(my) (puts("HAX MY ANUS") + strlen("HAX MY ANUS\n"))
Name:
Anonymous2012-09-09 19:29
fucking niggers
Name:
Anonymous2012-09-10 0:32
>>21
Write an error message to stderr, of course. The most likely cause of a write to stdout failing is a disk filling up when stdout is redirected to a file on said disk. If stderr is redirected somewhere else, your chances of recovery are much better.
>>28
If stdout is fucked, it's fucked. You're not going to magically recover it. The best you can do is print an error to stderr and then either move on or exit instead of dicking about trying to fix stdout.