You are on page 1of 14

Special Keywords

Embedded Software Essentials


C1M3V5
Allocated Data Characteristics
• Allocated Data can have varying Specified by utilizing
• Size • Variable types
• Access • Type Qualifiers
• Scope • Type Modifiers
• Location • Storage Classes
• Creation time • Compiler Attributes
• Lifetime • Specialized Functions

• Data allocation is not limited to Linker File outlines


static allocation at compile time, the memory
but also dynamic allocation at segments
runtime.
Data Locations Code Segment
Start
.intvecs
• Data Memory (Most Common) Address

• RAM
• Code Memory Data Segment
.text
• Read-Only Data Start
Address .data
• External Non-volatile Memory .const
• Non-Volatile Data .bss
.cinit
.heap .pinit
Non-Volatile Data
Start Segment (unused)
Address (unused)
End
.eeprom .stack End
End Address
Address Address
C Keywords
• Special C-Keywords can affect data allocation
• Variable Types
• Type Qualifiers
• Type Modifiers
• Storage Classes*

* Can apply to other references like functions


C Keywords
• Special C-Keywords can affect data allocation
• Variable Types
• Type Qualifiers
Type most directly affect the size of the data
• Type Modifiers
allocated
• Storage Classes
Examples:
• char, short, int, float, etc Sizes are
• Derived types Architecture
• Enumerated Types Dependent
• _Bool, _Complex (c99)
C Keywords
• Special C-Keywords can affect data allocation
• Variable Types
• Type Qualifiers
• Type Modifiers Const Type Qualifier
• Storage Classes • Allocates the data as a constant, will be
mapped to Read-Only Memory

const char VARA = ’a’;


const int VARB = 1;
Const Keyword Start
Code Segment

Address .intvecs
• Data will be constant & put in read-only
memory like flash
.text

• Sub-Segment name is application


.const
dependent
.cinit
• .rodata .pinit
• .const const char VARA = ’a’;
const int VARB = 1;
(unused)
End
Address
C Keywords
• Special C-Keywords can affect data allocation
• Variable Types
• Type Qualifiers Type modifiers modify the size and sign of data type
• Type Modifiers
Examples:
• Storage Classes
• unsigned
• signed
• short
• long
ARM:
short int VARA; 2 Bytes
long int VARB; 4 Bytes
long long int VARC; 8 Bytes
C Keywords
• Special C-Keywords can affect data allocation
• Variable Types
• Type Qualifiers
Storage Classes specify lifetime and scope of a data
• Type Modifiers
type
• Storage Classes
Examples:
• Auto auto int VARA;
static int VARB;
• Static extern int VARC;
• Extern register int VARD;
• Register
Auto Keyword Start Address
Data Segment

.data
• Automatically allocated and deallocated
data on the stack .bss
• Has a lifetime of a function or block
.heap
void foo(){
auto int vara;
int varb; (unused)

/* Other Code */
.stack
return; End Address
}
Static Keyword Data Segment
Start Address

• Data will persist in memory until .data


the end of the program .bss

.heap
• Static data can get stored in both
.data or .bss
static int VARA = 1; (unused)

.stack
static char VARB;
static int VARC = 0; End Address
Extern Keyword
Data Segment
• Declares a global reference defined in Start Address
another file to be visible by current file .data
• Can be bss or data
.bss
• Initial definition must be a global variable
.heap
extern int VARA; int VARA = 1;
extern char VARB; char VARB;
extern int VARC; int VARC = 0; (unused)
File1.c File2.c
.stack
End Address
Register Keyword
• Allocates Data directly in the CPU Microcontroller
• Used for repeated variable use with CPU Flash
high speed
• Not a guaranteed Registers

• Not commonly used


SRAM

Peripherals GPIO

Registers Registers
register int VAR = 1;
int A_BSS;
Data Segment int B_BSS = 0;
int C_DATA = 1;
const int D_RODATA = 1;
• Stack: Temporary Data Storage like
local variables void foo(int D_STACK_REG){
int F_STACK_REG;
int G_STACK_REG = 1;
static int H_BSS;
• Heap: Dynamic data storage static int I_BSS = 0;
static int J_DATA = 1;
char * ptr_STACK_REG;
• Data: Non-Zero Initialized global and ptr_STACK_REG = (char *)malloc(8);
static data
/* More Code Here */

free((void *)ptr_STACK_REG);
• BSS: Zero initialized and Uninitialized
global and static data return;
}

You might also like