Keil Logo

GENERAL: VARIABLES NOT KEPT IN ORDER


Information in this article applies to:

  • C51 Version 5.50
  • C251 Version 2.14
  • C166 Version 4.02

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

  • Refer to ORDER in the Cx51 User's Guide.
  • Refer to ORDER in the C166 User's Guide.

Last Reviewed: Friday, July 15, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.