VC programming-cross the road, look around

Source: Internet
Author: User
Tags define

When they were young, adults always taught children to "cross the road and look around." I do not know why, but because the big people nagging too many, so that all deeply imprinted in the mind, become the subconscious. Often when crossing the road, involuntarily have to look around. Grow up, gradually like to consider the question, always ask why: Why is "cross the road, look around" instead of "crossing the road, right and left to see"? A friend told me that is because the habit of Chinese words is about, men and women, young people and so on, like "showdown" not called "a male mother" is just a habit. However, I think the habit is to form, if every day to say "cross the road, right and left" to say more, but it is more customary to say that ~:)

In fact, think carefully, "cross the road, left and right to see" is a very reasonable words. China's vehicles are all driven on the right, so the first half of the way across the road (the process of walking from the road to the middle of the road) is always the vehicle coming from our left, and the last half of the process (from the middle of the road to the right side of the road) is always the vehicle from the right side to the left.

So, this proverb teaches us to look to the left to look to the right, even can say that the first half of the time can only look to the left, half of the time can only look to the right. If you turn the formula into reverse, you do nothing, and if you don't have the formula, the head will swing like a drum when you cross the street. (note 1).

Chinese people do a good job of summing up a formula, the internal strength of the mind, practice knives have knife spectrum, practice sword has sword tactic, even St. Wang Xi also wrote a book tactic (I forgot how many strokes, the brothers hint). Another example, "Journey to the Sun," said the Monkey King Huoyanshan when the hair was baked, so the left hand pinched a fire tactic rushed down. This shows that the formula is useful, the ability is big as Sun Dasan all use: Although you do not know how he came, but according to the formula to do the right-the ancestors have been validated before summed up as a formula handed down.

In fact, software development also has a lot of formulas, even if it is not clear, but do, always right. If you do not follow, you may have really stabbed the basket, or in the code buried in a temporary difficult to appear hidden dangers. Here is an example of the application of the formula in C (c + + I do not understand, do not shortcoming pull.) ~

For example, there is a formula called "to define macro constants or macro formulas, you must add parentheses," many people do not understand, so they do not add, the result is similar to the following questions:

#define NUM_A 100
#define NUM_B  25 * 2
#define int_div(a, b) a / b
float c;
c = int_div(NUM_B, NUM_A); //作者原意是 50/100,实际结果是 25 * 2 / 100, 结果没错
c = int_div(NUM_A, NUM_B); //作者原意是 100/50,实际结果是 100 / 25 * 2,结果错 了。
试想,如果我们就按照口诀来操作:
#define NUM_A (100)
#define NUM_B (25 * 2)
#define int_div(a, b) ( (a) / (b) )

And how could it be wrong? For example, there is a formula called "The header file is declared undefined". If you do not follow this formula, there will be problems. Like what:

//a.h
int max(int a, int b)
{
  return a>b?a:b;
}
//main.c
#include "a.h"
#include "a.h" //include 两遍后就会重复定义max(),结果出重复定义的错 。
int main()
{
  return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.