Field/Structure Alignment - Texas Instruments TMS320C2x User Manual

Optimizing c compiler digital signal processor
Hide thumbs Also See for TMS320C2x:
Table of Contents

Advertisement

Memory Model
6.1.7

Field/Structure Alignment

6.1.8
Character String Constants
6-8
When the compiler allocates space for a structure, it allocates as many words
as are needed to hold all of the structure's members. In an array of structures,
each structure begins on a word boundary.
All nonfield types are aligned on word boundaries. Fields are allocated as
many bits as requested. Adjacent fields are packed into adjacent bits of a word,
but they do not overlap words. If a field would overlap into the next word, the
entire field is placed into the next word. Fields are packed as they are encoun-
tered with the least significant bits of the structure word are filled first.
In C, a character string constant is used in one of the following ways:
To initialize an array of characters. For example:
-
char s[ ] = "abc";
When a string is used as an initializer, it is simply treated as an initialized
array, each character being a separate initializer. For more information
about initialization, see section 6.8, System Initialization, on page 6-31.
In an expression. For example:
-
strcpy (s, "abc");
When a string is used in an expression, the string itself is defined in the
.const section with the .string assembler directive, along with a unique
label that points to the string the terminating 0 byte is also included. For
example, the following lines define the string abc, and the terminating byte
(the label SL5 points to the string):
.sect
SL5
.string
String labels have the form SLn, where n is a number assigned by the
compiler to make the label unique. The number begins at 0 and is in-
creased by 1 for each string defined. All strings used in a source module
are defined at the end of the compiled assembly language module.
The label SLn represents the address of the string constant. The compiler
uses this label to reference the string in the expression.
If the same string is used more than once within a source module, the
string is not duplicated in memory. All uses of an identical string constant
share a single definition of the string.
Because strings are stored in the .const section (possibly in ROM) and
shared, it is bad practice for a program to modify a string constant. The
following code is an example of incorrect string use:
const char *a = "abc"
a[1] = 'x';
.const
"abc", 0
/* Incorrect! */

Advertisement

Table of Contents
loading

This manual is also suitable for:

Tms320c2xxTms320c5x

Table of Contents