Questions tagged [c]

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. from http://en.wikipedia.org/wiki/C_(programming_language)

C (pronounced "See", 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. Its design provides constructs that map efficiently to typical machine instructions, and therefore it found lasting use in applications that had formerly been coded in assembly language. It is highly efficient procedural oriented programming language, has emphasis on functions whereas latest object oriented programming languages having emphasis on data.

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 , which began as an extension to C.

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 micro-controllers to supercomputers.

Tag usage

Questions that are not related to microcontroller programming or embedded firmware should be asked at Stack Overflow.

When posting questions about C programming, please make sure to include:

  • Target system & compiler version, including the specific CPU/microcontroller part that is used.
  • Unless the question explicitly mentions which version of the C standard that is used, it is assumed that the current version is used. That is, whichever version of ISO 9899 that ISO currently lists as active. Please have this in mind when answering or commenting on questions tagged .
  • Relevant flags/switches passed to the compiler, assembler or linker if applicable.
  • Verbatim copies of compiler warnings or errors if applicable. Please post them as text and not as screen shots.
  • Snippets of source code identified as problematic by the compiler if applicable. Note that many compilers stay silent by default as long as they are able to compile your code, so you have to explicitly enable compiler warnings. With the widely used GCC for example, you should always pass -Wall -Wextra -pedantic on the command line.

Is it C, C++ or both?

This tag is for questions related to C, not C++. In some cases, you may be working with both and applying both tags is entirely appropriate. However, please refrain from using both tags in an effort to help your question reach a wider audience. After all, C++ answers won't help you solve the problem in C, and good C answers often do not describe the best approach in C++.

Important notes that may save you time

1606 questions
52
votes
9 answers

Using volatile in embedded C development

I have been reading some articles and Stack Exchange answers about using the volatile keyword to prevent the compiler from applying any optimizations on objects that can change in ways that cannot be determined by the compiler. If I am reading from…
Pryda
  • 1,241
  • 2
  • 19
  • 30
42
votes
5 answers

Who receives the value returned by main()?

I know that in computers, value returned by the main() function is received by the operating system. But, what happens in the main() function of a microcontroller?
user18118
  • 551
  • 1
  • 5
  • 5
41
votes
3 answers

What resides in the different memory types of a microcontroller?

There are different memory segments to which various types of data are put into from C code after compilation. I.e: .text, .data, .bss, stack and heap. I just want to know where each of these segments would reside in a microcontroller memory. That…
stenvar
  • 731
  • 2
  • 10
  • 17
37
votes
9 answers

Fast and memory efficient moving average calculation

I'm looking for a time and memory efficient solution to calculate a moving average in C. I need to avoid dividing because I'm on a PIC 16 which has no dedicated division unit. At the moment, I just store all values in a ring buffer and simply store…
sensslen
  • 473
  • 1
  • 5
  • 8
35
votes
2 answers

What is bit banging

I am new to microcontroller programming. I am using ATmega32-A controller and CodeVisionAVR compiler. I am using the waveform generator(AD9833) to generate a sinewave signal using SPI communication. I am able to generate the sinewave successfully.…
verendra
  • 1,223
  • 2
  • 14
  • 23
33
votes
7 answers

How do I use the printf function on STM32?

I am trying to figure out how to use the printf function to print to the serial port. My current setup is STM32CubeMX generated code and SystemWorkbench32 with the STM32F407 discovery board. I see in stdio.h that the printf prototype is defined…
user505160
  • 1,010
  • 5
  • 16
  • 26
32
votes
5 answers

C standard libraries on bare metal

I am mostly doing development on devices that have ported Linux so the standard C library provides lots of it's functionality through implementing system calls which have a standardised behaviour. However for bare metal, there is no underlying OS.…
TheMeaningfulEngineer
  • 961
  • 3
  • 11
  • 25
25
votes
2 answers

C coding design - function pointers?

I have a PIC18F46K22 and program it with the XC8 compiler. In the end, I'll have a system like a pc with stdin and stdout. So in the main loop there will be a function which is checking if there is new input. If there's input, a function will be…
user17592
24
votes
7 answers

For embedded code, why should I use "uint_t" types instead of "unsigned int"?

I am writing an application in c for an STM32F105, using gcc. In the past (with simpler projects), I have always defined variables as char, int, unsigned int, and so on. I see that it is common to use the types defined in stdint.h, such as int8_t,…
bitsmack
  • 16,747
  • 9
  • 52
  • 108
22
votes
7 answers

C - wrapping globals in a struct?

A firmware style question concerning C. I have some legacy code I am tidying up. One of the nasty features is global variables being scattered through the source files. I can make a few of them locals, which is fine. However, how to deal with the…
Dirk Bruere
  • 13,425
  • 9
  • 53
  • 111
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
20
votes
6 answers

Use of global variables in Embedded Systems

I started writing firmware for my product and I'm a rookie here. I went through many articles about not using global variables or functions. Is there any limit for using global variables in an 8 bit system or is it a complete 'No-No'. How should I…
Rookie91
  • 2,108
  • 4
  • 29
  • 46
20
votes
9 answers

Does the "Avoid using floating-point" rule of thumb apply to a microcontroller with a floating point unit (FPU)?

As a rule of thumb, I try to avoid using floating-point in my embedded system codebase. Floating-point variables are: Computation-intensive Not atomic (can cause problems in an RTOS application or with interrupts) Their precision can cause…
gbt
  • 671
  • 6
  • 17
19
votes
5 answers

How to implement critical sections on ARM Cortex A9

I am porting some legacy code from an ARM926 core to CortexA9. This code is baremetal and does not include an OS or standard libraries, all custom. I am having a failure that appears to be related to a race condition that should be prevented by…
CodePoet
  • 407
  • 3
  • 7
18
votes
4 answers

How does factory reset work?

All embedded devices includes a "Factory reset" option that allows the user to reset his device if something is wrong. I am developing a Firmware on an STM32 board. The firmware includes a boot loader that allows to upgrade the application via…
Pryda
  • 1,241
  • 2
  • 19
  • 30
1
2 3
99 100