C++ is a compiled general-purpose programming language that adds object-oriented features and other enhancements to the C language, which it is largely a superset of. It is popular for both embedded and PC software development.
Questions tagged [c++]
218 questions
183
votes
16 answers
Is C++ suitable for embedded systems?
A common question, here and elsewhere. Is C++ suitable for embedded systems?
Microcontrollers? RTOSes? Toasters? Embedded PCs?
Is OOP useful on microcontrollers?
Does C++ remove the programmer too far from the hardware to be efficient?
Should…

Toby Jaffey
- 28,796
- 19
- 96
- 150
22
votes
10 answers
Programming languages for electronics engineers
I am an Electronics and Communications Engineering student, before I got to college, I have been interested in programming and computer applications. I had focused on designing Windows applications and learning its techniques, but now, I feel that…

Siraj Muhammad
- 572
- 2
- 6
- 22
14
votes
2 answers
Avr-gcc using repeated addition instead of MULU instructions
I recently compiled some C++ code for the ATmega1284P in Atmel Studio and was analyzing the timings of some routines using my scope. To my surprise, a loop I thought I had optimized was taking longer than expected.
After taking a peek at the…

Hackstaar
- 886
- 6
- 22
13
votes
5 answers
C++ classes for I/O pin abstraction
I am looking for C++ abstractions for hardware I/O points or pins. Things like in_pin, out_pin, inout_pin, maybe open_collector_pin, etc.
I surely can come up with such a set of abstractions myself, so I am not looking for 'hey, you might do it…

Wouter van Ooijen
- 48,407
- 1
- 63
- 136
12
votes
3 answers
Microcontroller Sleep Race Condition
Given a microcontroller that is running the following code:
volatile bool has_flag = false;
void interrupt(void) //called when an interrupt is received
{
clear_interrupt_flag(); //clear interrupt flag
has_flag = true; //signal that we have…

TRISAbits
- 1,348
- 1
- 13
- 25
12
votes
2 answers
Version control of schematics and source code
I am developing an electronic device which has two parts: hardware (Eagle schematics) and firmware (C++ source code). I would like to track changes in both source code and schematics, but there are some points where I am not sure how to organize my…

Honza Vojtěch
- 465
- 6
- 13
11
votes
1 answer
Arduino and Interrupts: Fast way to get pin values
I use an Arduino Uno and already set it up to work with interrupts on digital pins 2, 3, 4 and 5 according to an explanation1 I found.
void setup() contains the following code to setup the interrupts.
//Endable Interrupts for PCIE2 Arduino Pins…

madc
- 251
- 2
- 7
9
votes
1 answer
Bug in Keil ARM compiler with interrupt handlers and C++?
I have a problem with writing interrupt handlers in Keil ARM compiler for LPC1114. When I write program in C++ and specify --cpp compiler option all code from interrupt handlers disappears, it is replaced with infinite loop. I wrote simple program…

x4mer
- 986
- 1
- 9
- 13
9
votes
6 answers
Concept of the static keyword from the perspective of embedded C
static volatile unsigned char PORTB @ 0x06;
This is a line of code in a PIC microcontroller header file. The @ operator is used to store the PORTB value inside the address 0x06, which is a register inside the PIC controller that represents…

Electro Voyager
- 147
- 1
- 8
9
votes
2 answers
MCU programming - C++ O2 optimization breaks while loop
I know people says code optimization should only bring out the hidden bug in the program, but hear me out. I am staying on a screen, until some input via an interrupt is met.
Here is what I see in the debugger. Notice the line inspected and the…

Daniel Cheung
- 225
- 2
- 6
9
votes
1 answer
While loop optimized away
I have the following code in my microcontroler program:
// Wait for ADC conversion to complete
while ( ( ADCSRA && _BS( ADSC ) ) == _BS( ADSC ) ) {}
Where ADCSRA is a register that will change its value once an analog conversion is completed and…

jippie
- 33,033
- 16
- 93
- 160
9
votes
1 answer
STM32 interrupts and C++ don't go well together
I set up TIM3 to fire an interrupt in my project and it just wouldn't work. I tried everything I could and still couldn't find whats the problem. Then I created a clean project and copy/pasted only the code that sets up TIM3 and interrupts and it…

John
- 1,361
- 2
- 12
- 23
9
votes
1 answer
How to enable c++11 support for Atmel Studio?
I am currently using Atmel Studio 7 and I need to enable c++11 support for it. I couldn't find any documentation about this topic. Moreover, I am not even sure it has c++11 support, yet.

ozgur
- 479
- 5
- 12
8
votes
7 answers
Programming a parallel port as digital I/O
I'm trying to use a parallel port from a computer as a form of cheap digital output to do various things (control motors, light LEDs, read limit switches, ect).
I want to know how to control the 8 data pins on a parallel port using C++, however…

Faken
- 165
- 1
- 2
- 9
8
votes
1 answer
Can an ATmega or ATtiny device signature be read while running?
While programming an ATtiny or ATmega, avrdude prints the device signature, in this example it is an ATtiny.
avrdude: Device signature = 0x1e910a
Can I read this signature on a running device using C++ code (avr-gcc)? For ATmega1280 there is a…

jippie
- 33,033
- 16
- 93
- 160