c programming - refresher - part iv
DESCRIPTION
C programming refresher from Embedded point of view. Fourth part talks about pre-processingTRANSCRIPT
![Page 1: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/1.jpg)
C Refresher
Team Emertxe
Day4
![Page 2: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/2.jpg)
Compiling a C program
![Page 3: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/3.jpg)
Compilation
C program consists of source code in one or more files
Each source file is run through the preprocessor and
compiler, resulting in a file containing object code
Object files are tied together by the linker to form a
single executable program
![Page 4: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/4.jpg)
Pre processing and macros
![Page 5: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/5.jpg)
Preprocessing
Preprocessing• Occurs before program compiled
• Inclusion of external files
• Definition of symbolic constants
• Macros
• Conditional compilation
• Conditional execution
All directives begin with #• Can only have whitespace before directives
Directives not C statements• Do not end with
![Page 6: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/6.jpg)
#include
Usage
Loading header files
• #include <stdio.h>
Programs with multiple source files
Header file
• Has common declarations and definitions
• structures, enumerations, function prototypes
• Extract commonality of multiple program files
![Page 7: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/7.jpg)
Symbolic constants
#define
• Symbolic constants
• Constants represented as symbols
• When program compiled, all occurrences replaced
Format
• #define identifier replacement-text
• #define MAX_ARRAY_SIZE 30
![Page 8: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/8.jpg)
Symbolic constants
Advantages
• Takes no memory
Disadvantages
• Name not be seen by debugger (only replacement text)
• Do not have specific data type
![Page 9: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/9.jpg)
Preprocessor directives
- Macros
Macro
• Operation specified in #define
• Intended for legacy C programs
• Macro without arguments
• Treated like a symbolic constant
Macro with arguments
• Arguments substituted for replacement text
• Macro expanded
• Performs a text substitution
• No data type checking
![Page 10: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/10.jpg)
Example
#define PI 3.14159
#define CIRCLE_AREA( x ) ( PI * ( x ) * ( x ) )
area = CIRCLE_AREA( 4 );
becomes
area = ( 3.14159 * ( 4 ) * ( 4 ) );
![Page 11: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/11.jpg)
Preprocessor directives
- Conditional compile
Control preprocessor directives and compilation
Cannot evaluate cast expressions, sizeof, enumeration
#ifdef BOARD_TYPE_1
#define REG_SIZE 32
#else
#define REG_SIZE 64
#endif
![Page 12: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/12.jpg)
Stay connected
About us: Emertxe is India’s one of the top IT finishing schools & self learning kits provider. Our primary focus is on Embedded with diversification focus on Java, Oracle and Android areas
Emertxe Information Technologies,
No-1, 9th Cross, 5th Main,Jayamahal Extension,
Bangalore, Karnataka 560046
T: +91 80 6562 9666E: [email protected]
https://www.facebook.com/Emertxe https://twitter.com/EmertxeTweet https://www.slideshare.net/EmertxeSlides
![Page 13: C Programming - Refresher - Part IV](https://reader034.vdocuments.mx/reader034/viewer/2022042813/54625ef4af7959a4058b49d9/html5/thumbnails/13.jpg)
THANK YOU