Embedded efficient programming (1)-concise and embedded programming

Source: Internet
Author: User

Embedded efficient programming (1)-concise and embedded programming

Two years of work experience: How to Implement embedded efficient programming.

1. Concept of efficient programming

  • High Performance and efficient programming
  • Precisely implement the reservation function
  • Low percentage of debugging time in the entire development cycle
  • Concise code
  • Code for easy maintenance
  • Efficient programming is to quickly write high-quality code.
2. Key Points of efficient programming

  • Concise
  • Clear
  • Flexible
  • Security
  • Unit Test
  • Design
3. Key Points of efficient programming: Concise and concise, which can be simply understood as a non-repetitive amount and code without Invalid code or logic.
3. 1. Use macros to replace constants.
double circle_area(double r){return 3.14 * r * r;}#define PI3.1415926#define float_tdoublefloat_t circle_area(float_t r){return PI * r * r;}
3. 2. Use macros to represent repeated calculation formulas or operations.
#define point_reset(p)((p % 4) < 2) ? (p / 4 * 4) : (p / 4 * 4 + 4)xxx = point_reset(xxx)yyy = point_reset(yyy)
3. 3. Use the same volume to express the same volume
PAudioBuf = malloc (a slightly complex computing expression exp );... Memcpy (pAudioBuf, src, a slightly complex computing expression exp); iAudioSize = a slightly complex computing expression exp; pAudioBuf = malloc (iAudioSize );... Memcpy (pAudioBuf, src, iAudioSize );
Funxxx(){for (i = 0; i < 16; i++){…}for (i = 0; I < 16; i++){}}Funxxx(){iCnt = 16;for (i = 0; i < iCnt; i++){}for (i = 0; I < iCnt; i++){}}
3. 4 General Code logic independent functions 3 and 5 define only one part 3 and 6 invalid logic judgment
Example 1 {... If (res) {return rs;} else {return 0 ;}// modify {... Return res ;}
Example 2 {... If (res) {return xxxx;} else {return 0 ;}} modify {... Return res? Xxx: 0 ;}
3. Applications of arrays 7
Example :{... If (0 = res) {return xxx1;} else if (1 = res) {return xxx2;} else if (2 = res) {return xxx3 }....} Modify: {vals [] = {xxx1, xxx2, xxx3 ,...};... Return vals [res];}
3. 8. template Application
double double_add(double a, double b){return a + b;} float float_add(float a, float b){return a + b;}int int_add(int a, int b){return a + b;}#define DECLARE_MATH_FUN(name, type, op) \type type##_##name(type a, type b) \{ \return (type)(a op b);\}DECLARE_MATH_FUN(add, int, +);DECLARE_MATH_FUN(add, float, +);DECLARE_MATH_FUN(add, double, +);DECLARE_MATH_FUN(sub, int, -);DECLARE_MATH_FUN(sub, float, -);DECLARE_MATH_FUN(sub, double, -);
3. 9 enemies of concise code

  • Copy and paste
  • Lazy programmers
  • Unthinking programmers
  • Ungrown programmers
  • Programmers with a sense of accomplishment based on the amount of code
3. Repeat code 10

  • Large program size
  • Increased maintenance costs
  • Easy to miss
  • Confusing and interfering with troubleshooting
  • Inconsistency may occur, causing program running exceptions.
The code is concise and written here for the time being, and will be updated in the future when you encounter typical problems.












What is embedded programming?

Simple: the name of the slice is cut-type system programming.
-----
What does an operating system need?
Real-time, multi-task, driver, and application.
----
A cutting system removes unnecessary drivers and adds a unique driver.
For example, I only need a beep, video drive, keyboard drive, and mouse.
----
What is software programming?
Variables, functions, and applications
What is embedded?
Memory, storage, multi-thread, and driver, provide underlying APIs to applications ,.

What do I need to know about embedded programming?

Embedded programming requires knowledge of C language, Linux, and ARM.

I just saw a very good article about how to learn embedded. It was a junior college student who introduced how to learn embedded and found embedded jobs, it introduces his learning methods and processes, and hopes to help you.

Junior college students are embedded into finding their work before and after -- learning examples

First, let me introduce myself. In, I got into a very bad specialized private school, and I learned a biology major. I won't say anything about the specific school name. In 10 thousand, I dropped out of school. I had to spend more than yuan a year in that school, but no one was studying. I really couldn't see the hope, so I dropped out.

After dropping out of school, I was confused. I didn't even graduate from college. I really don't know what I can do. I am struggling with what I can do. So after dropping out of school, I want to find a job for a while. Because I am not very talkative, I am not suitable to apply for a job. I want to apply for technical skills, but it hits the wall everywhere.

By chance, I heard about the embedded industry. I went to Xinhua bookstore that day and tried to find a book on the computer classification page. Later, a girl came over and asked me if I was reading a computer or not. I was interested in learning embedded. Then I introduced the current hot situation of embedded and told me how promising I was to learn embedded, I got a leaflet for Embedded training advertisement. After hearing her introduction, I felt itchy. I really wanted to learn my own technology and eat with my hands.

When I got home, I went online and checked the embedded systems. It is indeed a popular industry today, and it is also better to find a job. The salary is also relatively high. I made up my mind to learn embedded. So I went to the embedded training information, and I was confused. I don't know if the training was as good as they advertised, so I want to know what to do for a while.

Later, I learned from Baidu that I saw an article "How to Learn embedded", which encouraged me very much. I am an embedded expert who has no foundation. How can I learn embedded by myself, the article is well written, including how to learn and how to learn. He mentioned that one method is to watch videos, Because reading books is too boring and confusing, and many of them cannot be understood. I really agree with this. I can't read a few pages on my own.

I was wondering why others could learn by themselves, and I could! I have to believe in myself, so I want to learn by myself. If I do not learn, I will go to training again.

I decided to search for embedded videos. Although I found some embedded videos, they were not systematic. I wanted to find a video that could tell me how to learn, A set of videos from entry to mastery, a relatively complete set of information, it is best to have a teacher to teach, do not understand can ask.

Later, I found a good video, a video "embedded video tutorial-teach you how to learn embedded" launched in the embedded learning network. The tutorials in the video are not bad but complete, I can start from the basics. Video is not cheap, but I have to endure it. After all, it takes hundreds of dollars to buy a few books. Besides, they still have half a year of technical consulting and services, which is worth it.

I will not provide their URLs here. If you want embedded videos, you can search for them by yourself: Learn embedded videos with no basic skills.

Next I will introduce my learning process, hoping to help my friends who have no foundation as well as me.

After receiving the CD they sent me, I started to learn. Since I have no foundation, I started to learn from the simplest C language video tutorial, in fact, I still don't know much about it. I had to ask them. They were very enthusiastic and helped me solve the problem. I learned the C language for almost a week. Next I learned the basic commands of linux. I did some exercises on their linux virtual machines, typed the basic commands of linux, and wrote simple C language code, it takes about three weeks. I keep writing some simple code every day, so that after January, I basically mastered the basic operations of C and linux.

Next, I went to learn the video training courses provided by other people. They are a complete set of training courses. They are not much different from attending the training course. I have learned the basic principles of ARM for two months, I learned the concept of an embedded system and learned how to build an embedded environment. I also learned more about linux ...... remaining full text>

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.