Well I agree in part.. However I have always been a lone programmer, so the rules of programming do not apply to me. I would bet that the majority of programmers here are also embedded engineers who do the same style of programming,Programming is not about "how easy it is to write". It is about structure, abstraction, modularity, managing big projects, working in teams and passing the work to the next guy to continue. Without these things you can't build "big" things.
Well I agree in part.. However I have always been a lone programmer, so the rules of programming do not apply to me. I would bet that the majority of programmers here are also embedded engineers who do the same style of programming,
The whole reason behind C++ was for those reasons... C can be just a general programming tool.
However, when it comes to MCUs, things get different. Your primary task is to control hardware in real time. A lot of processing is done by built-in hardware modules which run in parallel and use DMA and interrupts. Your need to organize them and make sure all interrupts are handled and everything is taken care off. You need to be acutely aware of how fast your code runs or you risk blocking interrupts for too long and loose some of them.
C does not abstract away from OS. C tries to stay away from machine dependent details, but it does not abstract away from hardware. You have full control of register, memories, interrupts etc. using C. The compiler does not know how to set up timers, or use DMA. You always need to know your hardware. And you have full, and only, control of it using C.
Complex data structure is equally complex with asm.. what would change that. It is in your hands to design the datastructure you need. Data is data.. Using C does not mean you are automatically using heap memory and fragmenting everything. I rarely use heap memory. And C does not allocate heap memory. It is up to the programmer how he uses memory.
"Big" programming does not mean you need "big" memory. It means you are doing "big" things. Complex things. Things that makes your head spin fast unless you choose the right tool for the job.. write modular code, get organized.
"C is not far from asm really. It is just more productive way to code it. I would even bet that most C compilers produce better ASM than average hobby asm coder.
That is only very small part of the code that is not portable (and asm has the same problem). I write my code in well defined modules.. and I have lots of them. They are ansi-c and therefore very portable. I have modules that do data-analysis, work with datastreams like message parsers etc. Then I have modules for different kind of sensors, motor controllers, PID controllers, Fixed Point math. Every module is usually one pair of .c and .h files. Even a small project is usually 20 files or so. Usually my main.c file is very short. I call the main-file, or the main-function, "The Composition Root". That is where everything is initialized and set to run.Now, like you said, it doesn't really matter on MCU because you hard-code your register, memories, interrupts, DMA into your code. Once you do that, it is no longer portable.
I don't use heap to allocate memory for data-structures(or anything else). If I need a linked list, then I reserve an array of list elements according to "how many elements I need at most". That is much safer than allocating dynamically from heap. It is true that heap is not very practical on uC, but you don't need to use it. But, also, using heap with asm is just the same as using it in C. Absolutely no difference. So you can't say "Another advantage of C is lost".C is very good with complex data structures. You can allocate structures, interlink them, walk through them. But, to allocate them you need a heap. For example, you need to build a binary tree with elements of varying size. You cannot do that without a heap. It is not practical on MCU, so you don't use it. Another advantage of C is lost.
No wonder people have problems with pointers. Without a heap, they don't have anything for the pointers to point to.
True (also vice versa).One can write a very messy code in C, or one can write beatiful code in Assembler.
I think this debate has run it's course... We are talking about two separate items and trying to differentiate between them..
Of course we can't use a heap on little micro's... The last pic I used was a pic16f1828... 256bytes of data memory... Dynamic allocation is really only useful with RTOS's, where several tasks need to run... We can keep this going all year and get absolutely nowhere... If you want to program in C!! Good for you. If you want to program in C++! Well good for you too. If your project works go for it.... I don't care if you use pointers, placemats, binary indices, or whatever.
All I know is the name calling has started.... So If someone doesn't program the way you do, it doesn't make them ignorant!! If you want to use a shovel to knock nails in... Go for it...
I think this debate has run it's course... We are talking about two separate items and trying to differentiate between them..
Of course we can't use a heap on little micro's... The last pic I used was a pic16f1828... 256bytes of data memory... Dynamic allocation is really only useful with RTOS's, where several tasks need to run... We can keep this going all year and get absolutely nowhere... If you want to program in C!! Good for you. If you want to program in C++! Well good for you too. If your project works go for it.... I don't care if you use pointers, placemats, binary indices, or whatever.
All I know is the name calling has started.... So If someone doesn't program the way you do, it doesn't make them ignorant!! If you want to use a shovel to knock nails in... Go for it...
Talk about attacking forum members. Calm down. I enjoyed the debate. I know this same topic repeats itself twice a year, but still. Saying that somebody is ignorant is not "calling him names". I meant that he does not know what he is talking about. That's all. No need to be so aggressive.
I hope your not offended and will continue. I'm learning a lot, and will most likely re-read this several times.
I would go further too. We almost reached the logical conclusion that the important thing is to follow good programming practices and think about what you're doing regardless of the langauage you program in, but because of MisterT's temperament we had to stop. Now there's no other resort for him than to go to the nearest ABC store and start buying different sorts of meat for buger testing
I'm not offended. Just wondering why Ian so aggressively is against this debate.
I would like to here how asm programs are structured if done properly. I don't think I've seen any really well written asm programs here in the forum. Well, usually they are just code snippets.
Yeah, lets not go there in this thread.Sounds like the start of a good "Thread"
Especially, something like the word "Ignorant" here in the U.S. especially in the South, it maybe taken you are "calling" someone stupid or dumb (Offensive)
I didn't get upset or anything. It's just 3 am here in Finland.. have to sleep sometimes. I would like to here how asm programs are structured if done properly. I don't think I've seen any really well written asm programs here in the forum. Well, usually they are just code snippets.
I would like to here how asm programs are structured if done properly.
If Ian doesn't mind I will post an example. I don't really want to open a new thread for this.
Besides, MisterT expressedly said that he wants it here.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?