- Porting C++ code to C - 11 Updates
- Worst thing about 2020 C++ - 9 Updates
- Porting C++ code to C - 1 Update
Frederick Gotham <cauldwell.thomas@gmail.com>: Aug 17 04:51AM -0700 I'm porting C++11 code to C90 to run it on a microcontroller. My C++ code uses stuff from the headers <algorithm> <numeric> <functional>. I hear that "glib" is the best library for C that gives the functionality of the C++ standard library and also Boost. Looking through the 'glib' reference manual here though, I don't see anything similar to "std::next_permutation". Is glib the best thing to use for porting C++11 code to C if you're looking for functionality similar to <algorithm> <numeric> <functional>? |
Sam <sam@email-scan.com>: Aug 17 08:01AM -0400 Frederick Gotham writes: > the C++ standard library and also Boost. > Looking through the 'glib' reference manual here though, I don't see > anything similar to "std::next_permutation". That's because you shouldn't believe everything you hear. > Is glib the best thing to use for porting C++11 code to C if you're looking > for functionality similar to <algorithm> <numeric> <functional>? Well, I suppose it's just as good as any other random library that has nothing to do with C++, whatsoever. glib is part of the Gnome toolkit. It implements some higher-layer foundational constructs that the rest of this entirely C-based toolkit needs. It implements several, basic, vaguely C++-like constructs, but nothing even vaguely resembling algorithms, numerics, and functional C++ libraries. You're pretty much on your own, here. |
Frederick Gotham <cauldwell.thomas@gmail.com>: Aug 17 05:16AM -0700 On Monday, August 17, 2020 at 1:01:47 PM UTC+1, Sam wrote: > You're pretty much on your own, here. I just found the 'KLib' library: https://github.com/attractivechaos/klib Can't find "next_permutation" in it but it has some other cool stuff. |
David Brown <david.brown@hesbynett.no>: Aug 17 02:59PM +0200 On 17/08/2020 13:51, Frederick Gotham wrote: > I'm porting C++11 code to C90 to run it on a microcontroller. What kind of microcontroller are you talking about? For larger ones, C++11 is not an issue - many people use newer C++ on microcontrollers. (Often there are some limitations in what they do - in particular, most microcontroller software disables exceptions and RTTI.) For anything but the most outdated and brain-dead devices, C99 is fine if you are forced to go with C. But while C is a perfectly good choice for microcontroller programming, it is not a good choice if you are starting with C++ code. > My C++ > code uses stuff from the headers <algorithm> <numeric> <functional>. These are not likely to have much place in microcontroller programming. > I hear that "glib" is the best library for C that gives the > functionality of the C++ standard library and also Boost. If you heard that, you have not been listening in the right places. But start by saying what microcontroller you are targetting, roughly what resources it has (flash, ram, core, speed), and what toolchain you are thinking of using. |
Frederick Gotham <cauldwell.thomas@gmail.com>: Aug 17 06:09AM -0700 On Monday, August 17, 2020 at 1:59:14 PM UTC+1, David Brown wrote: > But start by saying what microcontroller you are targetting, roughly > what resources it has (flash, ram, core, speed), and what toolchain you > are thinking of using. PIC18F97J60 with onboard Ethernet. I'll use the Pickit2 (or Pickit 3 maybe) to program it, and I'll use MPLAB along with the 'Microchip' compiler. Non-volatile Program Memory = 128 kB (extendable to 2 MB by connecting another chip) Volatile Data Memory = 3 kB Maximum CPU clock = 40 MHz Datasheet is available here: https://www.mouser.co.uk/datasheet/2/268/39762f-1074147.pdf |
Scott Newman <scott69@gmail.com>: Aug 17 03:10PM +0200 Use Cfront, it can cross-compile every C++-code to C. |
David Brown <david.brown@hesbynett.no>: Aug 17 03:21PM +0200 On 17/08/2020 15:09, Frederick Gotham wrote: > Volatile Data Memory = 3 kB > Maximum CPU clock = 40 MHz > Datasheet is available here: https://www.mouser.co.uk/datasheet/2/268/39762f-1074147.pdf You decided to use that one, against advice? OK, you are on your own. Good luck trying to get it to run anything in standard C with much efficiency. |
Frederick Gotham <cauldwell.thomas@gmail.com>: Aug 17 08:13AM -0700 On Monday, August 17, 2020 at 2:11:14 PM UTC+1, Scott Newman wrote: > Use Cfront, it can cross-compile every C++-code to C. Worked back in 1994, not so sure about recent code. Anyway my code uses templates too. |
Scott Newman <scott69@gmail.com>: Aug 17 05:24PM +0200 >> Use Cfront, it can cross-compile every C++-code to C. > Worked back in 1994, not so sure about recent code. Anyway my code uses templates too. Google for the C++20-version. |
Vir Campestris <vir.campestris@invalid.invalid>: Aug 17 06:21PM +0100 On 17/08/2020 16:13, Frederick Gotham wrote: > On Monday, August 17, 2020 at 2:11:14 PM UTC+1, Scott Newman wrote: >> Use Cfront, it can cross-compile every C++-code to C. > Worked back in 1994, not so sure about recent code. Anyway my code uses templates too. Did I read correctly that your device has 128k of NVRAM and 3k of RAM? How big is the program on its current platform? Andy |
Juha Nieminen <nospam@thanks.invalid>: Aug 17 05:35PM > Did I read correctly that your device has 128k of NVRAM and 3k of RAM? I have had to develop for an STM8 system which has 32 kB of flash memory (for the executable binary) and 1 kB of RAM. And not like 20 years ago. This year. It is perfectly possible. You just have to watch for that 32 kB limit. |
Sam <sam@email-scan.com>: Aug 16 07:58PM -0400 > >where the co-routine idiocy originated. I strongly suspected it was more > >Microsoft-lobbied crap. > Yeah, I can't say I'm a fan either. They have a use case but so does setjmp/ Their use case is that multi-threaded performance on MS-Windows is notorious for being utterly craptastic; thread creation takes an eternity, etc… This is just Microsoft attempting to stuff the C++ standard with a multithreaded-like API that doesn't suck on Windows. > >priority, then this nosense. > Clang hasn't even implemented <=> yet which should be trivial. Not sure about > gcc. gcc has it. |
Juha Nieminen <nospam@thanks.invalid>: Aug 17 05:58AM > So, it shouldn't be surprising to see that Microsoft's compiler already > implements this garbage. Which is more supporting evidence that it's crap, > and will always be crap. Did you have an actual argument against them, or are you just going to throw tantrums and insults like a petulant child? |
David Brown <david.brown@hesbynett.no>: Aug 17 08:24AM +0200 On 17/08/2020 07:58, Juha Nieminen wrote: >> and will always be crap. > Did you have an actual argument against them, or are you just going to throw > tantrums and insults like a petulant child? There is also the obvious counter-argument that MS did not in any sense "invent" coroutines. Amongst others, they are discussed by Knuth - who describes subroutines (i.e., "functions" in C and C++) as just being special cases of coroutines. |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Aug 17 09:07AM +0200 On 17.08.2020 08:24, David Brown wrote: > "invent" coroutines. Amongst others, they are discussed by Knuth - who > describes subroutines (i.e., "functions" in C and C++) as just being > special cases of coroutines. The C++20 coroutines API (which is a misnomer because it does not support general coroutines but just continuations) devolved directly from Microsoft's API shipped with Visual C++ for a number of years. The standardization committee managed to uglify it considerably, in addition to its inherent ugliness, including uglification of keywords. But the changes are superficial, cosmetic: it is thoroughly a Microsoft thing, and arguing against that fact is, well, un-informed. ;-) - - - I did not myself implement but helped to implement coroutines in some microprocessor assembly (could it be Z80?) + Pascal in the early 1980's, at college. We had nice HP 64000 workstations... :) The only language I've used with real support for co-routines is Modula-2, which I used as a student in Edinburgh late 1980's on my first computer, an Atari 1040ST. I then implemented real co-routines for Turbo C++ in the 1990's, based on `longjmp` and some assembly. Unfortunately that TC++ code was enthusiastically used by someone working at a hospital in New York. I hope that code didn't hurt anyone. But. So, I have "always" found co-routines interesting and sort of useful, sort of seeking them out, testing the feel of them. But I find the C++20 thing disgusting. It does not appeal to me at all. - Alf |
Juha Nieminen <nospam@thanks.invalid>: Aug 17 08:27AM > "invent" coroutines. Amongst others, they are discussed by Knuth - who > describes subroutines (i.e., "functions" in C and C++) as just being > special cases of coroutines. It would be hard to argue that Microsoft invented coroutines given that they were first discussed as far back as in 1958, and languages like Simula 67, BCPL and Modula-2 have support for coroutines. |
boltar@nowhere.co.uk: Aug 17 10:43AM On Sun, 16 Aug 2020 19:58:52 -0400 >ous =20 >for being utterly craptastic; thread creation takes an eternity, etc=E2=80= >=A6 Though I suspect not as bad as the utterly hopeless win32 process creation model. |
Sam <sam@email-scan.com>: Aug 17 07:07AM -0400 Juha Nieminen writes: > > and will always be crap. > Did you have an actual argument against them, or are you just going to throw > tantrums and insults like a petulant child? Yes, I do: they suck. |
Sam <sam@email-scan.com>: Aug 17 07:08AM -0400 David Brown writes: > > tantrums and insults like a petulant child? > There is also the obvious counter-argument that MS did not in any sense > "invent" coroutines. Nobody claimed that they did. They simply crammed it into the C++ standard because Windows sucks at doing actual threads. |
Juha Nieminen <nospam@thanks.invalid>: Aug 17 05:30PM >> Did you have an actual argument against them, or are you just going to throw >> tantrums and insults like a petulant child? > Yes, I do: they suck. So a petulant child you are. I will thus be treating you as one. |
ram@zedat.fu-berlin.de (Stefan Ram): Aug 17 12:08PM Newsgroups: comp.lang.c++,comp.lang.c >I hear that "glib" is the best library for C that gives the >functionality of the C++ standard library and also Boost. There's no way you can imitate RAII and classes using a library. >Looking through the 'glib' reference manual here though, I >don't see anything similar to "std::next_permutation". In 2010, I posted this code to a German newsgroup: #include <stdio.h> #include <stdlib.h> #include <string.h> static inline void swap( size_t a[], size_t const i, size_t const j ) { size_t const tmp = a[ i ]; a[ i ]= a[ j ]; a[ j ]= tmp; } int next ( size_t const length, size_t * const array ) { size_t j = length - 1; while( j > 0 && array[ j - 1 ]>= array[ j + 1 - 1 ])--j; if( j == 0 )return 0; else { size_t l = length; while( array[ j - 1 ]>= array[ l - 1 ])--l; swap( array, j - 1, l - 1 ); { size_t k = j + 1; l = length; while( k < l ){ swap( array, k - 1, l - 1 ); ++k; --l; }} return 1; }} void print ( size_t const length, char const * const text, size_t const * const array ) { for( size_t i = 0; i < length; ++i )putchar( text[ array[ i ]]); putchar( '\n' ); } /* Prints all permutations of "word" */ int main( void ) { char const * const text = "word"; size_t const textlength = strlen( text ); size_t * const array = malloc( textlength * sizeof( size_t )); if( array ) { for( size_t i = 0; i < textlength; ++i )array[ i ]= i; do { print( textlength, text, array ); } while( next( textlength, array )); free( array ); } else fprintf( stderr, "no array.\n" ); } |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment