Here in this article, I am planning to brief you through the Standard library of AVR-GCC. By the term “Standard Library” we mean the “Standard header” files like “stdio.h”, we commonly see in C programming language. Have you ever used String Formatting in ANSI C? Did you use Standard library functions? If you are familiar with C programming language, then you must be familiar with standard header files we write in the beginning of the program like “#include stdio.h“, “#include stdlib.h” , “#include conio.h” etc etc. The most important of all header files is the header file -which simply means “Standard Input Output header file”. It is by adding this header file, we make the compiler recognize and interpret standard library functions like “Scanf” (to get input) and “Printf” (to output to a device like display or pinter).
printf(“Hello! % d %f %c %s”,a,b,c,d);
Now I hope you have got some idea about what I’m going to tell. Before going deep into this article, I would like to show you some tutorials I have written before, which will be useful for you.
Okay! Now I am going to show you an important difference between programming in C and for the Avr-Gcc. In C programming, you just need to write the command printf(“Hello! % d %f %c %s”,a,b,c,d); to send these string of characters all together to the output device, like a display or a printer.The “printf()” function makes it easier for you. It takes care of the conversion portion.
In AVR studio there the end compiler is AVR-GCC framework. A header file named ‘stdio.h’ comes here too. The ‘printf()’ function prototype is defined there. But here it demands complete description of a routine to send a single character to the display device or a routine that will send a string of characters. The prototype of the routine must match with the return types and arguments as demanded by the end compiler. Else the function will malfunction or will not get compiled at all (resulting in error).
Now the complete code of the “printf()” and its core functions are quite big. It involves string formatting including the floating point conversation. The implementation of integer conversion is much smaller. So AVR Studio offers three flavors of the ‘printf()’! One implements moderate functionality of the string formatting (signed integer conversion), another low (only unsigned integer conversion), and the last one offers full functionality of that (including signed and unsigned floating point and same of that integer conversion). To use full or lower functionality, you’d have to request the compiler to compile those specific implementations. Otherwise, the unimplemented formatting would place a ‘?’ character in the formatted string. To do this you’d have to modify some settings. You’ll find it in this article.
Read more: Standard Library & String Formatting for AVR