5037 views|20 replies

7815

Posts

57

Resources
The OP
 

[Old post in the section] A 51-post from ten years ago [Copy link]

 
This post was last edited by Xin Xin on 2018-9-5 00:44 Friendly summary: The main topic mentioned below: In that old post, in fact, its problem is nothing more than mixing C++ programming and some special keywords of C51. For us who develop single-chip microcomputers, I think we will face these two problems sooner or later, but we cannot ignore that C is still the only popular language in the single-chip microcomputer world at present and for a long time to come. So, what would you do to not exclude C++ and special machine platforms, but to better and smoothly face the fact that "single-chip microcomputers, only C cannot be broken"? Welcome to discuss. This moderator doesn't have much else, but he has a lot of chips. He will spend all his wealth just for your wonderful answers! In the world of Queue, when the Front reaches the end, it will bite back, start from 0, and continue to move forward. Today in the moderator group, xxoxk goddess said that if I don't move, she will kill me, but I already have countless unfinished black history, and there is nothing to play with various C small grammar questions. I am not as versatile as @队长, who knows a little bit of every language. After thinking about it, I have to learn from the goddess and dig up old posts. Where should I start digging? I'll do it once and for all. Today I will record that [Programming Basics] has a total of 23 pages. Based on the three principles of irresponsibility, initiative and persistence, I started from the earliest post at the bottom... Unexpectedly, I was lucky. This post has a lot to say... This content was originally created by EEWORLD forum user Xin Xin. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source


This post is from Programming Basics

Latest reply

I never resist new things. Back then, trains could not run faster than horse carriages. This is normal. As long as you think it is suitable, just do it with your heart.  Details Published on 2018-9-7 15:13
Personal signature

强者为尊,弱者,死无葬身之地

 

7815

Posts

57

Resources
2
 
I don't know if these old posts will be deleted naturally one day. For the sake of the completeness of this post, I decided to briefly summarize the content of this brother's post: He actually wanted to move a graphic menu source code used on VC to 51, but he encountered many problems with this code. He was very upset and felt that "the difference between PC and KEIL is really huge." The following is the code. At that time, there was no CODE format. It was too uncomfortable to look at it, so I reorganized it
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

7815

Posts

57

Resources
3
 
#include
#include
#include
char MenuOne_Date[3][14]={"1 Module Text","2 Tools","3 About Me"}; //Change the MenuName[] here and below to unsigned. Why is there an error? char MenuTools_Date[4][11]={"1 SetTime","2 Dingshi","3 MiaoBiao","4 Book"}; struct NodeDate { char seq; char MenuName[17]; }; struct MenuNode { NodeDate data; ///Keil uvision said there is an error here struct MenuNode *parent; struct MenuNode *firstchild; struct MenuNode *next brd; }*Previous,Module_Struct,Tools_Struct,AboutMe_Struct,SetTime_Struct,DingShi_Struct,MiaoBiao_Struct,Book_Struct; void BuildNode(struct MenuNode * Self,struct MenuNode *Parent_Node,struct MenuNode *Firstchild_Node, struct MenuNode *Nextbrd_Node,char seq,char MenuName [17]) { Self->parent=Parent_Node; Self->firstchild=Firstchild_Node; Self->nextbrd=Nextbrd_Node; Self->data.seq=seq; strcpy(Self->data.MenuName,MenuName); } void Initial_MenuStruct(void) { //First level Menu BuildNode(&Module_Struct,NULL,&SetTime_Struct,&Tools_Struct,10,MenuOne_Date[0]); BuildNode(&Tools _Struct,NULL,NULL,&AboutMe_Struct,11,MenuOne_Date[1]); BuildNode(&AboutMe_Struct,NULL,NULL,&Module_Struct,12,MenuOne_Date[2]); Previous=&Module_Struct; //Module sub-layer Menu BuildNode(&SetTime_Struct,&Module_Struct,NULL,&DingShi _Struct,20,MenuTools_Date[0]); BuildNode(&DingShi_Struct,&Module_Struct,NULL,&MiaoBiao_Struct,21,MenuTools_Date[1]); BuildNode(&MiaoBiao_Struct,&Module_Struct,NULL,&Book_Struct,22,MenuTools_Date[2]); &SetTime_Struct,23,MenuTools_Date[3]); } void main(void) { Initial_MenuStruct(); for(int i=0;i<3;i++) { //cout<data.MenuName<<" "<data.seq<data.MenuName,Previous->data.seq); Previous=Previous->nextbrd; } Previous=Module_Struct.firstchild; for(i=0;i<4;i++) { printf("%s\t%d\n",Previous->data.MenuName,Previous->data.seq); Previous=Previous->nextbrd; } } This program is fine in vc. But in the keil environment, I deleted the main function here (my project has main in other .c), the structure was not changed, and compiled. Error: struct MenuNode { NodeDate data; struct MenuNode *parent; struct MenuNode *firstchild; struct MenuNode *nextbrd; } error 1: syntax error near 'NodeDate' error 2: missing ';' before 'data' [/code]
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

7815

Posts

57

Resources
4
 
This post was last edited by Xin Xin on 2018-9-5 00:46 This post is not long, and it ends before the next page. The answers on the first few floors hit the point, which refreshed my impression of this old post. I have read the old posts in the embedded section before, and they are simply outrageous spam and advertising posts. It must have been very difficult for Nong Jie back then. In the end, there are two main problems encountered in this code: 1., Of course, the author said that he forgot to remove it for a moment, and he also knew that this was done when he used C++ under VC. Yes, this is one of the standard libraries (header files) of C++, not in the C standard library, let alone in C51; 2. An accident, the variable he defined used the keyword data - to be honest, I haven't used 51 for too long, anyway, I didn't notice it.
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

6040

Posts

204

Resources
5
 
Why doesn't the leader post? Once he posts, he will be in the top three
This post is from Programming Basics
 
 
 

7815

Posts

57

Resources
6
 
However, in the replies, there are several places where I found that someone's answer found the crux of the problem, but the statement itself is problematic. Of course, this is actually not a big problem. I am no longer so entangled in the statement. After all, it is said that in the book C Programming by K&R, the ancestor of C, the master said that the array was passed as an address to the function at this time, and the array degenerated into a pointer. I remember that time, I hurt that guy on the spot through QQ, but he gave me a screenshot of the original English book. My mood at the time was like this , and my face was like this But then I thought about it, C was invented by others, what can I say? Besides, it's just a statement, is it really that important? So gradually I didn't care much, but in order to make this post more technical and prevent me from being killed by the goddess, I decided to talk about it.
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

7815

Posts

57

Resources
7
 
I won't say more, it's the middle of the night. Let's take the first two floors as examples. example 1:
C, not C++ If you don't use typedef, you have to use struct MenuNode. struct MenuNode{ ... }; //There has to be a semicolon here"
First of all, there is no difference in the definition of typedef in C and C++. And his statement is misleading. In fact, typedef is just a renaming of the data type. There are several ways to write it. Many times we just happen to have seen this way of writing and are familiar with it, so we mistakenly think that this is a special way of writing. In fact, it is not the case. MenuNode is obviously a structure definition. Since it is a structure, the identifier MenuNode must be followed by a struct before, which has nothing to do with redefinition. Otherwise, where can you find a data structure or keyword called MenuNode? I dare not say where else, and there is definitely no such thing in the C standard library.
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

7815

Posts

57

Resources
8
 
example 2:
#include

There is no such library in KEIL!! MCU is not PC
First of all, this answer is wrong. Because the iostream.h library has nothing to do with whether it is a PC or not, and even has nothing to do with KEIL. In essence, we can think that in the context of ordinary people's speech, the so-called PC actually means WINDOWS or LINUX or other operating system host environment. When we say KEIL, we generally refer to IDE. But whether it is OS or IDE, they have nothing to do with the language library itself. And iostream itself is one of the standard libraries of C++. So, do you think it is in KEIL? If (I am not sure) there is a C51 compiler that supports C++, then your KEIL actually "has iostream.h", and on the PC, if you specify a C project instead of a C++ project, then your PC does not have "iostream.h".
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

7815

Posts

57

Resources
9
 
Finally, I'll leave you a small question to stimulate your thinking. It's actually very simple. I don't know if you have noticed it. C51 is a remote dialect of C language. Since we became familiar with STM32, the C language development of microcontrollers has become more and more indistinguishable from the so-called C on "PC". So, including me, we have long forgotten the keyword data. It is even less likely that we will remember that in addition to data, there are actually idata and xdata. I thought I would never see this thing again in my life. But recently, because the project I was working on required to reach automotive grade, I used NXP's MCU, S32K144 for the first time. In its C statement, I saw the long-lost data keyword again (in fact, this time, this key modifier was so long that I couldn't even remember how to type it out). So, there is a problem - we can't expect that C will always be the same as our "standard C on PC". We may not have many opportunities to write a serious C program on PC in our lifetime. However, at least for me, I really hope that no matter what microcontroller I use in the future, I don't need to worry about these idata xdata... There are similar ideas. I want to port a code snippet on PC VC to a microcontroller. It is a very common idea and there is nothing wrong with it. But it is still a small idea to give me iostream at every turn. What if there are a lot of vector contain in the code? Nowadays, more and more microcontrollers have already supported C++. In fact, C++ is indeed more suitable for writing code than C in some occasions. It is not only simple, but also the compiled HEX runs at the same speed. Therefore, it is foreseeable that one day in the future, I will definitely want to use C++ to implement a module, and even I may have to port a C++ library, and this library is only written in C++. For example, you can try to find a graphics library suitable for microcontrollers other than ucgui/emwin? So, the above questions, please ask more engineers who only want to use C or are only suitable for C to write microcontroller programs - they are not wrong. At this time, how can we make these things transition more slowly and smoothly? This is an open question, and your answer is welcome.
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

7815

Posts

57

Resources
10
 
lcofjp posted on 2018-9-5 00:28 Why don’t you post? Once you post, you will be in the top three
Captain, hello. Captain, goodbye.
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

7171

Posts

195

Resources
11
 
Whenever I saw someone programming like this, my first impression was that he was a great programmer.
This post is from Programming Basics
 
 
 

1w

Posts

204

Resources
12
 
Xinxin, you are so cute. I am blown away! Thank you for posting so much
This post is from Programming Basics
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
 
 
 

7815

Posts

57

Resources
13
 
okhxyyo posted on 2018-9-5 08:28 Xinxin, you are so cute. I am blown away! Thank you for posting so much
Yes, goddess. The goddess is always right
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

7815

Posts

57

Resources
14
 
Common Ze 1 posted on 2018-9-5 08:15 Every time I saw such programming, my first feeling was that it was a great god
What great god. I feel like this is just a broiler.
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

122

Posts

2

Resources
15
 
The underlying SDK of ESP32 seems to be written in C++.
This post is from Programming Basics
 
 
 

7815

Posts

57

Resources
16
 
lcn1992 posted on 2018-9-5 14:01 The underlying SDK of ESP32 seems to be written in C++.
Well, I have interviewed two large companies before. They also require microcontrollers to be written in C++.
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

1368

Posts

6

Resources
17
 
1) Choose the right platform that is suitable for the project. 2) Product development is project-oriented. It is a hooligan to talk about development without considering the project.
This post is from Programming Basics
 
Personal signature专注智能产品的研究与开发,专注于电子电路的生产与制造……QQ:2912615383,电子爱好者群: void
 
 

7815

Posts

57

Resources
18
 
Lazy Cat Loves Flying published on 2018-9-6 08:25 1) Choose the right platform, just fit the project 2) Product development is project-oriented, and talking about development without taking into account the project is just hooliganism
Brother, I completely agree with what you said. But what do you mean?
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

1368

Posts

6

Resources
19
 
Xin Xin posted on 2018-9-6 17:10 Brother, I completely agree with what you said. But what do you mean?
I mean, whether it is C++ development or C development, it is good if it is suitable for rapid development. Whether it is 8-bit MCU or 32-bit MCU, it is good if it is suitable for the project.
This post is from Programming Basics
 
Personal signature专注智能产品的研究与开发,专注于电子电路的生产与制造……QQ:2912615383,电子爱好者群: void
 
 

7815

Posts

57

Resources
20
 
Lazy Cat Loves Flying Published on 2018-9-7 12:58 I mean, whether it is C++ development or C development, it is good if it is suitable for rapid development. Whether it is 8-bit MCU or 32-bit MCU, it is good if it is suitable for the project
Oh, yes, yes. I have heard too many people in reality resist hearing C++.
This post is from Programming Basics
 
Personal signature

强者为尊,弱者,死无葬身之地

 
 

Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list