Goraxium
Posts: 122
Joined: Tue Jan 26, 2016 1:42 pm

Re: Learning C / C++

Sat Mar 05, 2016 3:26 pm

davenull wrote:never start learning C(++) on a Raspi....
Not entirely sure I agree with your sentiments there. Learning C/C++ was a huge pain in the past, but a decent IDE makes everything a breeze (mostly (I still avoid the standard C++ like the plague because of the 50 errors it will generate from not knowing when it will cast a char[] to a string (slightly exaggerated))).

Do us all a favour, and install Code::Blocks. The hardest part from there will be interpreting errors in your own code (which Code::Blocks will help you with). Adding libraries is done in a pretty little window. You can compile single files, or create a project and have different parts built and linked together without messing with makefiles or anything complex. The only person making this difficult for you, is you.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Learning C / C++

Sat Mar 05, 2016 3:39 pm

davenull wrote:as I stated:
never start learning C(++) on a Raspi....
A little over 35 years ago I learned C on a PDP11/40 system running Unix v6.

There were no online manuals (not enough disk space), so everything was in print form. The processor had 256KB of core memory. There was no networking. We had dumb "glass teletype" terminals to work on. Screen editors hadn't yet become popular.

What can I say... How about "kids of today - get off my lawn"

-Gordon
--
Gordons projects: https://projects.drogon.net/

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: Learning C / C++

Sat Mar 05, 2016 3:41 pm

I'm currently absolutely fine with Geany, but about code::blocks I surely will have the same problems about downloading, installing, and configuring all the single libs, the paths, the #includes, and the compile and make/build parameters - now having managed that after 6 months of efforts and many setbacks.
But after having done that, I can access GPIOs (wiringPi, pigpio), openVG graphics, UART, I2C (even i2c-0 !! :twisted: ), access conio-like keyboard functionality, and even have pthread multitasking by different priorities. Still struggling with make and makefile though.

As I said: after 6 months, and after all that was just about the basic setups to be able to simply starting to write my proprietary programs.

On Arduino, all that, comparatively, in all over 1 week, and for Arduino I was an absolute complete beginner!!

That is the point which made up the difference in learning C/C++.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6226
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Learning C / C++

Sat Mar 05, 2016 4:01 pm

You're making a good case for NOT starting with an arduino. It seems to have made things more difficult for you in the long run.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Learning C / C++

Sat Mar 05, 2016 4:09 pm

davenull wrote:
On Arduino, all that, comparatively, in all over 1 week, and for Arduino I was an absolute complete beginner!!

That is the point which made up the difference in learning C/C++.
Sorry, but I don't think you learned much more than how to copy & paste and use other librarys/classes.

For example, you said you didn't know what the -> operator was... And here you are writing neural nets...

-Gordon
--
Gordons projects: https://projects.drogon.net/

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: Learning C / C++

Sat Mar 05, 2016 4:10 pm

actually....: no, because I chose Arduinos just because I didn't want to have to do anything with low level hardware and OS and make or makefile or commandline or ssh or putty stuff - I wanted to have a IDE which does all that odious and hated fumbling for me, and as I found that IDE at Arduino's I finally stayed with Arduinos.

I never would have managed to program all my extensive and elaborate projects (like my Arduino neural nets) if I had to struggle with all the low-level crap, but thanks to the IDE I could focus on programming. Finally I don't want to be a C nerd or Linux hacker, I simply want to write programs which simply work (either if C or not-quite C).


and about the neural nets: yes, they work! :)
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Goraxium
Posts: 122
Joined: Tue Jan 26, 2016 1:42 pm

Re: Learning C / C++

Sat Mar 05, 2016 5:37 pm

davenull wrote:I'm currently absolutely fine with Geany, but about code::blocks I surely will have the same problems about downloading, installing, and configuring all the single libs, the paths, the #includes, and the compile and make/build parameters - now having managed that after 6 months of efforts and many setbacks.
Installing things on Linux is as simple as 'sudo apt-get install', or, in most cases these days, 'git clone'+ 'make' + 'make install'. You rarely have to do more than that. Almost every recently developed tutorial will run you through that in easy step by step instructions. It's not hard.

Linking the libraries and setting compiler flags is done in a GUI in Code::Blocks. The only time that ever starts to get hard is when you're tweaking the output to change the filenames (which you shouldn't really need to do (unless you get bored like I did)).

The headers you're complaining about *cannot* be avoided. Whether you use C/C++, Java, Python, or just about anything and everything that isn't written in assembly (and I'm not even sure about that one). How else will the compiler know you want to use another piece of code that you haven't written yourself?

When I first started programming, all I had was a compiler and a bit of example code. No instructions, no documentation, no tutorials, no internet. Nothing. Just try and fail. I still didn't let it stop me from doing what I wanted to do.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: Learning C / C++

Sat Mar 05, 2016 6:47 pm

no, sure, but you don't see the point:
It's the overcomplicated fumbling with millions of nitty-gritty details to get everything prepared.
I myself am now finally starting to program my programs, but what a forced march to finally get there! After 6 months preliminary work and setbacks!

the #include headers are no issue of course. But they also are more ectensive than it might be inevitably necessary:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <errno.h>
#include <pthread.h>
#include "VG/openvg.h"   
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"
#include <wiringPi.h>
#include <wiringSerial.h>
#include <softPwm.h>
all that just for GPIO, graphics, I2C, and UART.
hell, that's long enough to sink a ship!

In Arduino it's

Code: Select all

#include <SPI.h>
#include <TFT.h> 
#include <Wire.h>
that's it.

the same about build parameters
g++ -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -o myfile myfile.c -lshapes -L/opt/vc/lib -lOpenVG -lEGL
For Arduino I don't need any.

I don't have to install all the libs, they are already in the Arduino libraries folder and just have to be #included.
I don't have to do all this stuff:
http://www.mindstormsforum.de/viewtopic ... 689#p67768
http://www.mindstormsforum.de/viewtopic ... =15#p67785
For Arduino it's already there, GPIO acces is just read/write digital, read/write analog, gladly wiringPi offers similar functions.

I don't have to patch all system entries like this
http://www.mindstormsforum.de/viewtopic ... =15#p67813
For Arduino it's already finished and ready to use.

Always the same: before being able to use a lib, it's 1 week or even much more for preparation the OS, the files, and everything, that is SO annoying!
Why do you think does it takes 3 entire websites to show what one has to do for Geany, openVG, GPIOs, UART, and I2C?
Because one has to do all and everything from the scratch, nothing is "already there": 6 months for setting up all that.
And having all that already availalbe is what would be actually needed if it was suitable for beginners.

Once having done that, I can start programming, Geany is (mostly) configured correctly, I wouldn't change that IDE anew - so now I'm fine, I have almost mastered the biggest hurdles (as it seems FTM), I just have started programming now a remote control.
What a success!
Just curious about the next unexpected setback.

But all over, a challenge and strain which is not reasonable and not acceptable for a C-learning (complete) newbie IMO.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
PeterO
Posts: 5736
Joined: Sun Jul 22, 2012 4:14 pm

Re: Learning C / C++

Sat Mar 05, 2016 8:56 pm

What this all shows is that you've also failed to understand how to build a application that is logically divided into multiple source files. You should not have a source file that needed all those libraries and include files.

A properly designed application would have separate source files for GPIO, openVG etc etc.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Goraxium
Posts: 122
Joined: Tue Jan 26, 2016 1:42 pm

Re: Learning C / C++

Sun Mar 06, 2016 1:39 am

Here's what you use:
davenull wrote: Arduino:

Code: Select all

#include <SPI.h>
#include <TFT.h> 
#include <Wire.h>
C/C++:

Code: Select all

//SPI + Wire
#include <wiringPi.h>
#include <wiringSerial.h>
#include <wiringPiSPI.h>
#include <wiringPiI2C.h>
#include <softPwm.h>
//TFT
#include "VG/openvg.h"   
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"
all that just for GPIO, graphics, I2C, and UART.
I simplified it for you. I even threw in the I2C and SPI headers.

As for everything else, if you're seriously going to compare it to the Arduino compiler, dump the rest of the header includes into another header file, and add that to the compiler's source files, and leave it out of your program, because that's exactly what the Arduino compiler does (from my understanding of it).

Here's an interesting idea... Why don't you write a program that generates a header that includes every single header from /usr/include and all of it's subdirectories, save it somewhere, and use that instead? That way you'll never have to include anything special ever again...

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: Learning C / C++

Sun Mar 06, 2016 10:21 am

I personally am now finally fine with it how it is. This topic is not about me, but about beginners, I can just tell you about the pitfalls, the hurdles, the shortcomings, and the setbacks of using C on a Raspi, being a newbie.

Besides the completely installed programming environment of all and everything, the advantage of Arduino is: you have lot of setup guides and tutorials (e.g., "Arduino Playground" - I don't think that the one who had chosen that name for it actually had a very lucky hand though), and you have an IDE which
a) covers all the confusing low level stuff (by Wiring and Processing where it once arose from), and
b) which provides context-senstive help to all GPIO, UART (Serial), I2C (Wire) and whatever kind of commands.

Nothing of that is available for the Raspi , starting with a guide for beginners for the very first steps, the first small programs, how to learn more about the details, no coherent overview at all (well, maybe except that small "Quick Guide" which I now wrote by myself as an extract of my laborious explorations).

Then you have in the Arduino IDE integrated examples about every common command: (see below)
Having all this, a beginner will get quick results, which is motivating for learning more, a big positive reinforcement from an educational point of view.

And that's what a beginner needs if he wants to use C for programming, and just this is what's missing for Raspberry users, which is the reason why I regard the Raspi platform as not suitable for complete beginners to C/C++.

ps, @Goraxium,
these following libs need to be #included for Raspi, but not for Arduino, because Arduino includes all of them (or their equivalents) already automatically if needed or used, so no need to include them explicitely:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <sys/ioctl.h>
#include <stdint.h>
some of the other ones I listed are needed because they are used by some of the #included libs itself.
But indeed I forgot 1 to mention for Arduino:
either Timer.h or DueTimer.h or Scheduler.h (depending on special purposes)
Attachments
ArduinoExamples400.jpg
ArduinoExamples400.jpg (42.24 KiB) Viewed 1654 times
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Goraxium
Posts: 122
Joined: Tue Jan 26, 2016 1:42 pm

Re: Learning C / C++

Sun Mar 06, 2016 11:34 am

davenull wrote:ps, @Goraxium,
these following libs need to be #included for Raspi, but not for Arduino, because Arduino includes all of them (or their equivalents) already automatically
You obviously didn't read what I wrote... And with that, I think I'm going to stop watching this thread...

I wish you luck with whatever it is you're working on.

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: Learning C / C++

Sun Mar 06, 2016 11:37 am

I have no problem with listing all the libs and headers, it should only show the whole amount of settings which are needed to make Raspi C programs able to compile and run, compared to Arduino. I personally know them now, but not every newbie does, right from the start.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Learning C / C++

Sun Mar 06, 2016 12:06 pm

So far off topic that it's serving no purpose.

Return to “C/C++”