![]() |
#1 |
JSR FFD2
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 305
Karma: 1045
Join Date: Aug 2008
Location: Rotterdam, Netherlands, Europe, Sol 3
Device: iliad
|
![]()
Hello developers,
I'm experimenting with contenLister and thinking about using C++ for some parts. Biggest advantage are: - easier (and cleaner) initialisation of structs (constructors) - better grouping of structs and corresponding functions - constants instead of defines - easier memory management (cleanup in destructors) Here is my current opinion - use C++ for future development: yes, but just simple stuff (no complex class hierarchies etc) - use C++ strings: maybe (if runtime c++ libs ar already on Iliad, and memory footprint of executables doesn't grow to much - use STL (vectors, linked lists...) probably not (I expect big memory usage) What do you think? I think this is an important choice... probably needs some thinking and experimenting ![]() Happy hacking, |
![]() |
![]() |
![]() |
#2 |
Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 345
Karma: 3473
Join Date: Apr 2007
Location: Brooklyn, NY, USA
Device: iRex iLiad v1, Blackberry Tour, Kindle DX, iPad.
|
Check out the iPDF viewer code. It's written in C++, at least partially. So programming in C++ is certainly possible.
As for the contentLister, I agree that converting some parts to C++ could offer advantages for developers. I really don't know much about how complex that would be or how it would change the program, but if you think it can be done it might be worth investigating. Long term, I think we need to determine where we want to go with the contentLister. One possibility that I like is to hack up the contentLister into two parts, backend and frontend. The backend would take care of all of the hardware handling, forwarding keypresses to X, etc. etc. The idea would be to handle all the dirty details and allow normal programs to run normally in X without needing to have special modifications. Then we could take an existing file manager, add a custom skin and some file handling abilities, and use that as the "frontend" that deals with opening files etc. Of course, the contentLister is already set up to deal with the registry, manifest files, and other details. So it might be better, as you suggest, to just revise the contentLister to make it cleaner. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
JSR FFD2
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 305
Karma: 1045
Join Date: Aug 2008
Location: Rotterdam, Netherlands, Europe, Sol 3
Device: iliad
|
![]()
Hi,
If you want to compile contentLister with c++ files, here is how to start. It is important that main() gets compiled with the c++ compiler... 1: make a working copy of contenLister Code:
cp -r contentLister cppLister cd cppLister Code:
after the line 'AC_PROG_CC', add a line with 'AC_PROG_CXX' Code:
< AC_CONFIG_SRCDIR(src/main.c) > AC_CONFIG_SRCDIR(src/main.cpp) 3: goto the sources: Code:
cd src rm -rf .deps # necessary if you have compiled this stuff before Code:
< contentLister_SOURCES = main.c \ > contentLister_SOURCES = main.cpp \ 5: convert main.c to main.cpp mv main.c main.cpp edit main.cpp as follows: Code:
before the first #include add a line: extern "C" { just before main() add a line: }; // end of extern "C" Code:
cd .. autoreconf --install --force ./configure --host=arm-linux --build=i686 --prefix=/usr --datadir=/usr/share Code:
cd src make I hope this helps someone, took me a while to figure it all out... Happy hacking! Tip: If you forget some step, and get errors: restart from scratch (a clean copy Tip: This looks like a nice simple FAQ on combining C and C++: http://www.parashift.com/c++-faq-lit...c-and-cpp.html Last edited by hansel; 11-25-2008 at 04:19 PM. Reason: forgot to mention Makefile.am |
![]() |
![]() |
![]() |
#4 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 423
Karma: 1517132
Join Date: Jun 2006
Location: Madrid, Spain
Device: quaderno, remarkable2, yotaphone2, prs950, iliad, onhandpc, newton
|
Hi!
Warning: heavily opinionated post ![]() I think that it's better to use C for libraries and use whatever you want for programs (be it C++, D, or your favorite scripting language). I also think that splitting contentLister into a backend library and a user-replaceable front-end program is the best route, but that is for the future. IMHO it's better to first fix the current one. And about C++: the only drawback for applications is the added dependency of libstdc++, which is bound to the gcc version used (unlike the libc, you have to use that libstdc++ with your program, a newer version doesn't work). For a project such as the iliad OS, this is not that relevant, as we know what libstdc++ will be installed in all the iliads. OTOH, I generally prefer coding in C over C++... there are less surprises although you end writing a little more code ![]() |
![]() |
![]() |
![]() |
#5 |
Fanatic
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 584
Karma: 914
Join Date: Mar 2008
Device: iliad
|
From my days of embedded developing, c++ was out of question, because the libstc++ takes 1MB of memory! While this might be negletable today, that day, when the device operated with 8MB of RAM it was an unbearable load.
Personally, when you don't design the application on paper with classes in first place, I'd highly advice against the use of c++. Otherwise you get more problems as solutions with it. Also most projects that are abole to sustain I've seen which are using c++ are very specific which parts of the c++ language are permitted to be used by developers. Projects that take c++ as whole without any restrictions are IMHO doomed to fail. You cannot believe how complex this language can become. And just because you can write some classes, doesn't mean other coders are suddendly using some strange constructs you have never seen before. For example I for one hate reference parameters. I'm no fan of templates, as I'm ever fail to read anyone else template code. And I as almost anybody else fear have a deep fear of multiple inheritance. Just to name a few. I think the GNOME (C) vs. KDE (C++) race has shown, you can develop really versatile hugh projects with C as well. (I know GNOME "misuses" the preprocessor a lot, to simulate a class structure, but is pretty okay IMHO). |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Fanatic
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 584
Karma: 914
Join Date: Mar 2008
Device: iliad
|
Quote:
For structs, you can just as well provide an "create_mystruct()" function for every structure you are doing, which allocats its memory and initialises it. I know there are some mroe things a c++ constructor can do. But for the uses here descriped create_mystruct() should do perfectly. About grouping. This just needs coder discipline. And when I'd think yes the way for exmpale java does it, does group things better, by default especially c++ is there just a worse as c as you can provide the function implementation just anywhere. Only the defintition has to be with the structure. Not so hard to archieve with a little editor descipline also. C has constants as well. Or at least as far as I know this is implemented exactly as good or worse than in c++. Memory management also. If you don't have the descipline to be very careful when to allocate and destruct stuff, and when to destruct stuff when no parts of it are no longer being pointed to, c++ is only making things worse for you, as debugging just become a tad more difficult. I like C, because everything you see is 99.9% like the processor behaves (as long you don't active gcc -O3), there is no magic happening anywhere. On the other hand in C++ the compiler does a lot of stuff in background. (Like calling destructors for a start, or duplicating code because of templates, or using pointers when you think you see it, (reference parameters); not calling destructors because you reference parametered a class and forget about it. Or calling a destructor while having a poitner to the class but run out of its context already. And so on. C++ is fine as long everything runs well, and you don't have to think about stuff really happening. But when things run wrong, using ddd is 100ooo times more exhausting... |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
iLiad Code to accelerate FBReader page-flip on iLiad | ericshliao | iRex Developer's Corner | 18 | 04-23-2010 03:28 AM |
iRex Releases iLiad Source Code | Adam B. | iRex | 26 | 11-06-2008 09:50 AM |
iLiad iRex hints at releasing all the iLiad code | drago | iRex Developer's Corner | 50 | 10-22-2008 10:31 AM |
iLiad Is source code of iLiad image viewer available? | ericshliao | iRex Developer's Corner | 1 | 01-16-2008 02:24 AM |