Programming c on raspberry pi

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Hi
I am looking to program in c on the raspberry pi 3.
It comes installed with NOOBS.
Do i need to install anything else to get my c programs up and running ie complier or OS.
I am a newbie to the raspberry PI so not sure.
Thanks in advance.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Also note that any compiler you find will probably default to C++
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Thanks for the information. Even if the compiler defaults to c++, i think i can still use c ? Is that not correct?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Thanks for the information. Even if the compiler defaults to c++, i think i can still use c ? Is that not correct?

C++ is more strict with types than C. You'll find that some C code will require explicit type-casting in order to compile.

Also there are more reserved words in C++ and if you choose one as your variable (or more likely you are compiling some code where someone else has used one) then you'll have some trouble.

If you want a longer list, see here.
 

LukeDupont

Apr 15, 2018
19
Joined
Apr 15, 2018
Messages
19
It might do you some good to familiarize yourself with Linux. Grab an ISO of Ubuntu or Linux mint, install it on a virtual machine like virtualbox or an unused PC laying about, and use it for a few weeks as your main computer. Learn to install packages, find your way around the terminal, and compile using gcc. You might even find you like it better than Windows or MacOS, if you're like me.

But, the reason I say to do that is because the raspberry pi is a stripped down, bare bones computer running a stripped down, bare bones installation of Debian with some odd configuration stuff thrown on top, so you may find it a bit challenging compared to a "normal" Linux distribution at first.

That said, Linux, the Raspberry Pi, and C/C++ are all wonderful, and you'll learn a lot about all aspects of computers and programming if you stick with it.

I think if you do that, most of your questions will be quickly answered. Maybe find some C tutorials on youtube that are aimed at compiling on Linux, and not just using some IDE (which, granted, you could also use instead. Code Blocks comes to mind).

Edit: Okay, I'll answer some of these questions directly.

"gcc" and "g++" are the gnu c compilers that will be installed, or at least available in the repositories of any Linux Distro.

Open a terminal and type "gcc -v"
If it outputs version info, gcc is installed.

Otherwise, install it with the command "sudo apt install gcc"
"sudo" is for super user do, and will prompt you for a password. Asterisks won't appear as you type - just type it and press enter.
"apt install" tells apt, your package manager, to install a package.
"gcc" is the GNU C Compiler package that you're installing.

To then compile a c file, let's say "hello.c", type:
gcc hello.c -out 'hello'
This will make a binary file called "hello" which you can run by typing "./hello"

You might also find programs like "cowsay", "htop", "nano", and "vim" to be fun or useful to mess around with while learning. Try typing them into the terminal and seeing what happens :)
 
Last edited:
Top