یه نوشته ساده و تمیز در مورد pre processor ها
https://www.programiz.com/c-programming/c-preprocessor-macros
https://www.programiz.com/c-programming/c-preprocessor-macros
Programiz
C Preprocessor and Macros
The C preprocessor is a macro preprocessor (allows you to define macros) that transforms your program before it is compiled. In this tutorial, you will be introduced to c preprocessors, and you will learn to use #include, #define and conditional compilation…
اگه مثل من فردا امتحان دارید، میتونید پست های اینجا رو بخونید:
https://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered/184682
بهترین کامنتهایی که توی کد نوشتین.
برای خودم اینا جالب بود:
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))
Stack Overflow
What is the best comment in source code you have ever encountered?
واقعا conditional compilation به همراه ماکروها توی سی، قدرت خیلی زیادی دارند. (و البته ترسناکی)
کد کامل رو اینجا ببینین:
https://github.com/dmcrodrigues/macro-logger/blob/master/macrologger.h
#ifdef debugالان اگه این برنامه با فلگ debug کامپایل بشه، اون log توی stderr اتفاق میافته، اما اگه معمولی کامپایل بشه هیچ لاگی وجود نداره. جالب تر اینکه هیچ اثری از لاگ توی فایل کامپایل شده هم وجود نداره و روند اجرای برنامه رو اصلا کند نمیکنه.
#define LOG(message) std::cerr << message << std::endl
#else
#define LOG(message)
#endif
کد کامل رو اینجا ببینین:
https://github.com/dmcrodrigues/macro-logger/blob/master/macrologger.h
GitHub
macro-logger/macrologger.h at master · dmcrodrigues/macro-logger
A simplified logging system using macros. Contribute to dmcrodrigues/macro-logger development by creating an account on GitHub.
چرا و چه زمانی در سی do-while false در سی نیاز داریم؟
https://stackoverflow.com/questions/4674480/do-whilefalse-pattern
https://stackoverflow.com/questions/4674480/do-whilefalse-pattern
Stack Overflow
do while(false) pattern
Possible Duplicate:
Why use apparently meaningless do-while and if-else statements in macros?
Why is the do while(false) necessary in the macros below?
#define LOG(message, ...) \
do { \
Lock<
Why use apparently meaningless do-while and if-else statements in macros?
Why is the do while(false) necessary in the macros below?
#define LOG(message, ...) \
do { \
Lock<
🔥1