ARM Technical Support Knowledge Articles

VARIABLES NOT KEPT IN ORDER

Applies to: General Topics

Answer


Information in this article applies to:


SYMPTOMS

I am using the ORDER compiler directive in my source code and I have declared several variables that I wish to place in memory in the same order. When I examine the symbol table in the map file, they are not kept in the same order that I declared them in. Why?

CAUSE

The order is not necessarily taken from the variable declarations, but the first use of the variables. For example, in the following files:

header.h

extern unsigned char foo;
extern unsigned int bar;

test.c

#include "header.h"
unsigned int bar;
unsigned char foo;

foo is stored in memory first followed by bar. This is because the foo variable is referenced first (by the extern declaration).

RESOLUTION

Make sure that in all declarations and externs your variables are declared in the order you require. An alternative solution is to delare a structure containing the variables you wish to keep in order.

This behaviour is changed in C166 Version 4.05 and later to take the variable order from the variable declarations. You may download the latest updates from the Keil Website.

MORE INFORMATION

ATTACHED FILES

Request the files attached to this knowledgebase article.

Article last edited on: 2005-07-15 12:47:03

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential