نوشته‌های ترمینالی
2.74K subscribers
425 photos
12 videos
32 files
2.28K links
Download Telegram
بخشی از سورس‌کد stdio توی /usr/include


/* C89/C99 say they're macros. Make them happy. */
#define stdin stdin
#define stdout stdout
#define stderr stderr
اگه مثل من فردا امتحان دارید، میتونید پست های اینجا رو بخونید:
https://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered/184682

بهترین کامنت‌هایی که توی کد نوشتین.
برای خودم اینا جالب بود:

This seems to stop morons from messing my code...

// Autogenerated, do not edit. All changes will be undone.




// sometimes I believe compiler ignores all my comments



#define struct union
// is very helpful in memory constrained systems.



return 1; # returns 1



/* This is O(scary), but seems quick enough in practice. */
followed by four nested for-loops


try {

} finally {
// should never happen
}



long long ago; /* in a galaxy far far away */



// I am not sure if we need this, but too scared to delete.



/* Please work */



/* You are not meant to understand this */


// no comments for you
// it was hard to write
// so it should be hard to read



// I have to find a better job



// hack for ie browser (assuming that ie is a browser)



try {

}
catch (SQLException ex) {
// Basically, without saying too much, you're screwed. Royally and totally.
}
catch(Exception ex)
{
//If you thought you were screwed before, boy have I news for you!!!
}


long time; /* know C */



// I can't divide with zero, so I have to divide with something very similar
result = number / 0.00000000000001;
(متاسفانه این رو بارها و بارها گذاشتم من!)




/**
* If you don't understand this code, you should be flipping burgers instead.
*/



/* Ah ah ah! You'll never understand why this one works. */



catch (Ex as Exception)
{
// oh crap, we should do something.
}



public GetRandomNumber()
{
// Chosen by a fairly rolen dice
return 12;
}




// This is crap code but it's 3 a.m. and I need to get this working.



// For the sins I am about to commit, may James Gosling forgive me



# Limit length of buffer to try to send, because some OSes are too
# stupid to do so themselves (ahem windows)
return self.socket.send(buffer(data, 0, self.SEND_LIMIT))
واقعا conditional compilation به همراه ماکرو‌ها توی سی، قدرت خیلی زیادی دارند. (و البته ترسناکی)

#ifdef debug
#define LOG(message) std::cerr << message << std::endl
#else
#define LOG(message)
#endif

الان اگه این برنامه با فلگ debug کامپایل بشه، اون log توی stderr اتفاق می‌افته، اما اگه معمولی کامپایل بشه هیچ لاگی وجود نداره. جالب تر اینکه هیچ اثری از لاگ توی فایل کامپایل شده هم وجود نداره و روند اجرای برنامه رو اصلا کند نمیکنه.

کد کامل رو اینجا ببینین:
https://github.com/dmcrodrigues/macro-logger/blob/master/macrologger.h