General > General Technical Chat
How many people code in C these days, and if so, why?
Wolfgang:
--- Quote from: nctnico on May 12, 2020, 05:18:14 pm ---
--- Quote from: Wolfgang on May 12, 2020, 04:05:49 pm ---Some thoughts to C++ on microcontrollers with limited memory:
IMHO, a really silly idea. Dynamic memory needs a memory manager, an this needs to take care of
fragmentation, free space recovery, garbage collection... Causing nondeterministic execution times, out of memory errors
--- End quote ---
That is a myth and thus completely wrong. For starters: C++ doesn't even has a garbage collector :palm:
--- Quote from: Nominal Animal on May 12, 2020, 03:19:12 pm ---
--- Quote from: madires on May 12, 2020, 03:07:17 pm ---Arduino is C++, just saying. ;D
--- End quote ---
Ever tried to use an exception in Arduino? No? That's what I thought.
Arduino is not C++, but an unspecified subset of it. You could call it freestanding C++, I guess, as opposed to normal hosted C++, because C++ leaves just about everything 'implementation defined' in freestanding environments.
That was one of my questions earlier, BTW. Can you call it C++ if you are only allowed to use a small subset of the features of C++? Especially when that subset is not described exactly anywhere? I feel like saying it is C++ is misleading to newcomers/programmers, and will lead to frustration.
--- End quote ---
But the same is true for C. There is a lot from the standard library you can't use. File I/O for example. Malloc & free are also troublesome to say the least.
--- End quote ---
No language standard specifies how memory that is no longer needed is handled. Thats specific to a runtime component. :palm:
And believe me, a lot of intelligent algorithms have been written to handle this. Problem. Efficient / Fast / Deterministic. Choose any two.
coppice:
--- Quote from: Wolfgang on May 12, 2020, 05:47:46 pm ---No language standard specifies how memory that is no longer needed is handled. Thats specific to a runtime component. :palm:
And believe me, a lot of intelligent algorithms have been written to handle this. Problem. Efficient / Fast / Deterministic. Choose any two.
--- End quote ---
Many languages are specified with their run time environment, and are not really separable from it. Java assumes a garbage collecting environment, for example.
SiliconWizard:
--- Quote from: nctnico on May 12, 2020, 05:18:14 pm ---
--- Quote from: Wolfgang on May 12, 2020, 04:05:49 pm ---Some thoughts to C++ on microcontrollers with limited memory:
IMHO, a really silly idea. Dynamic memory needs a memory manager, an this needs to take care of
fragmentation, free space recovery, garbage collection... Causing nondeterministic execution times, out of memory errors
--- End quote ---
That is a myth and thus completely wrong. For starters: C++ doesn't even has a garbage collector :palm:
--- End quote ---
Some of you are quick to shoot, aren't you?
The "garbage collection" argument he made was wrong indeed - C++ doesn't inherently have a garbage collector indeed. SO yes, remove that silly point.
The rest still applies - dynamic memory allocation, even without garbage collectors, CAN cause nondeterministic execution times - unless you use very specific allocators that are certainly not the ones that ship with the compiler. And of course that requires properly checking for successful allocation one way or another, which can be messy (or untractable - sometimes developers just don't know how to gracefully handle an out of memory condition.)
That's why dynamic allocation is frowned upon, or even forbidden if you follow rules from some safety-critical guidelines. If you have to follow this rule, properly using C++ is not impossible, but much harder than it looks.
--- Quote from: nctnico on May 12, 2020, 05:18:14 pm ---
--- Quote from: Nominal Animal on May 12, 2020, 03:19:12 pm ---
--- Quote from: madires on May 12, 2020, 03:07:17 pm ---Arduino is C++, just saying. ;D
--- End quote ---
Ever tried to use an exception in Arduino? No? That's what I thought.
Arduino is not C++, but an unspecified subset of it. You could call it freestanding C++, I guess, as opposed to normal hosted C++, because C++ leaves just about everything 'implementation defined' in freestanding environments.
That was one of my questions earlier, BTW. Can you call it C++ if you are only allowed to use a small subset of the features of C++? Especially when that subset is not described exactly anywhere? I feel like saying it is C++ is misleading to newcomers/programmers, and will lead to frustration.
--- End quote ---
But the same is true for C. There is a lot from the standard library you can't use. File I/O for example. Malloc & free are also troublesome to say the least.
--- End quote ---
Yes, but that's not exactly at the same level. What he mentioned for C++ is at the language level itself, which is a lot more problematic - basically there are settings where you can't use some language features, which is confusing for programmers. OTOH, libraries are a slightly different matter: I don't think any of what you mentioned is a mandatory part of the C standard. File I/O and memory allocation are all optional, if I'm not mistaken. OTOH, a lot of advanced C++ features that could be problematic on small embedded targets are NOT optional as per the standard.
The point is: the right subset to use is hard to define, is usually NOT defined clearly and largely depends on each developer. Not an ideal situation.
Picuino:
Arduino has 2k of ram. It is near impossible to do a good memory management with such a minimal amount of resources.
Normally, libraries work only with static memory, with the variables defined by default with each class.
Printf isn't even used because of the large amount of memory it consumes.
madires:
--- Quote from: Nominal Animal on May 12, 2020, 03:19:12 pm ---
--- Quote from: madires on May 12, 2020, 03:07:17 pm ---Arduino is C++, just saying. ;D
--- End quote ---
Ever tried to use an exception in Arduino? No? That's what I thought.
Arduino is not C++, but an unspecified subset of it. You could call it freestanding C++, I guess, as opposed to normal hosted C++, because C++ leaves just about everything 'implementation defined' in freestanding environments.
--- End quote ---
Is there only one true machine language or one real BASIC? No! There are many flavours of each language. But there are also standards defining some specific variant of a language, like C++17 (ISO/IEC 14882:2017) or C18 (ISO/IEC 9899:2018).
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version