Questions tagged [c]

For questions pertaining to compiling C programs on the Raspberry Pi.

C (pronounced like the letter C) is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system.

Although C was designed for implementing system software, it is also widely used for developing portable application software.

C is one of the most widely used programming languages of all time and there are very few computer architectures for which a C compiler does not exist. C has greatly influenced many other popular programming languages, most notably C++, which began as an extension to C, and Java.

Design

C is an imperative (procedural) systems implementation language. It was designed to be compiled using a relatively straightforward compiler, to provide low-level access to memory, to provide language constructs that map efficiently to machine instructions, and to require minimal run-time support. C was therefore useful for many applications that had formerly been coded in assembly language.

Despite its low-level capabilities, the language was designed to encourage cross-platform programming. A standards-compliant and portably written C program can be compiled for a very wide variety of computer platforms and operating systems with few changes to its source code. The language has become available on a very wide range of platforms, from embedded microcontrollers to supercomputers.

279 questions
31
votes
1 answer

How can I detect that I'm compiling for Raspberry Pi?

As Raspberry Pi needs a bit of special code (I'm talking about C/C++) for accessing some hardware features (e.g. a call to bcm_host_init()). I'm looking for a reliable and elegant way to detect this automatically. I don't think there are any…
Tapio
  • 693
  • 1
  • 6
  • 9
31
votes
2 answers

How does memory-mapped I/O addressing work?

How does memory-mapped I/O addressing work? I'm trying to understand a sample supplied I2S: Anyone got it running?. Configuring Clocks: #define BCM2708_PERI_BASE 0x20000000 #define CLOCK_BASE (BCM2708_PERI_BASE + 0x101000) /*…
Dog Ears
  • 2,027
  • 6
  • 19
  • 28
26
votes
4 answers

Which CPU flags are suitable for gcc on Raspberry Pi?

gcc takes the -mcpu= (or -march=) flags to produce optimized code for a particular CPU type. There's a plethora of arm variants, and the gcc Arm target also provides numerous FPU types. Which -mcpu=/-march= flags and -mfpu= flags are the…
nos
  • 1,106
  • 2
  • 10
  • 14
20
votes
5 answers

Write an OS for Raspberry Pi in C

I already found the Baking Pi tutorials, but they only use assembly language. I followed the first lessons, but I am already wondering how to use C instead. I mean, there is a reason they invented higher-level languages. I tried just compiling the C…
11684
  • 455
  • 1
  • 3
  • 13
16
votes
3 answers

Can I program C within a nice IDE on desktop computer for the RPi

I'm from a Microsoft Windows development background, I'm happy with the IntelliSense and code navigation features, is it possible for me to install an IDE, such as Eclipse, [I'm assuming it's probably best for me to make the jump and dual-boot…
Dog Ears
  • 2,027
  • 6
  • 19
  • 28
12
votes
2 answers

Get PI's temperature using C

I know you can get the temperature using the tool vcgencmd but I was wondering if there is any API I can use in C to get the temperature programatically without reading the stdout of vcgencmd ?
opc0de
  • 654
  • 5
  • 11
  • 18
12
votes
3 answers

Push buttons getting too many events

I am writing a mp3 player that writes info to a LCD display, I'd like to convert it from using the keyboard to using push buttons but I'm constantly getting too many key presses. I've tried pull up and falling/rising edge but I'm still getting the…
linuxgnuru
  • 625
  • 11
  • 21
10
votes
3 answers

Can't access shared libraries when running with sudo

I'm trying to get a demo working writing PCM to the I2S; I've created a small demo program that gives an error when I run with the following command ./demo stereo_small.wav can't open /dev/mem So I run with the this command sudo ./demo…
Dog Ears
  • 2,027
  • 6
  • 19
  • 28
10
votes
2 answers

Turn LED on and off with switch

I'm trying to write code to get an LED to turn on when it is off and to turn off when it is on using a tactile push button switch. I've written what I believe to be is the right code with the wiringPi library, but I can only get it to turn on when…
Mark Luna
9
votes
5 answers

GPIO Interrupt debounce

I was following this guide, Raspberry Pi GPIO interrupts in kernel space, to create a kernel module handling GPIO interrupt. The problem is that this code doesn't have software debounce implemented. Can you please give me advice about how software…
Flavio Barisi
  • 357
  • 1
  • 4
  • 10
9
votes
2 answers

How to use Java to read/write data to/from the header pins?

I just got Java running on my Raspberry Pi which took a lot more screwing around than i had hoped. I want to be able to read/write data to/from the header pins from Java. How can I do this? Do I need to write a driver or some sort with C first in…
John
  • 925
  • 1
  • 8
  • 12
9
votes
3 answers

Controlling Raspberry Pi GPIO with c and Python

I was searching for C and Python Libraries which support Pi4.
Milliways
  • 62,573
  • 32
  • 113
  • 225
8
votes
3 answers

How to compile C files in terminal

Question Can someone please tell me how to compile from the command line in a clear, concise way. Preferably, my programs will be written in a real text editor (such as leaf pad). Background I am a complete n00b when it comes to Linux, C, and the…
xxmbabanexx
  • 3,278
  • 7
  • 36
  • 56
8
votes
2 answers

GPIO library for C

I want to utilize the GPIO pins on my Raspberry Pi 2, but I'd rather not use Python since I personally dislike the language. However, I cannot seem to find any information regarding the use of C, only Python. Is there an official C API? If so, where…
user112513312
  • 221
  • 4
  • 6
8
votes
1 answer

Reading GPIO states using C

I've implemented this example to familiarize myself with basic GPIO programming in C. The code demonstrates how to write to GPIO pins but does not explicitly state how to read the state of pins. I suspect that WiringPi will ultimately be a better…
bobthechemist
  • 546
  • 1
  • 6
  • 18
1
2 3
18 19