ARM Technical Support Knowledge Articles

LIMITS ON FUNCTIONS WITH VARIABLE-LENGTH ARGUMENT LISTS

Applies to: C51 C Compiler

Answer

QUESTION

Can you clarify the requirements on the number of bytes passed to functions with variable-length argument lists (like the printf function) when using the C51 compiler?

ANSWER

Programs are created using C51 pass arguments in fixed memory locations. Arguments are not passed on the stack. For this reason, there are some limitations placed on functions, like printf, that utilize a variable-length argument list (vararg).

* By default, in SMALL and COMPACT memory model, the C51 compiler reserves 15 bytes of space for passing arguments to printf (as well as other functions with variable-length argument lists).

* By default, in LARGE memory model, C51 reserves 40 bytes of space for arguments.

You may use the MAXARGS compiler directive to change the number of bytes reserved. Note, however, that large numbers will rapidly consume memory in SMALL and COMPACT memory models.

The number of bytes of reserved space refers to how many bytes the arguments to the function require. For example:

  printf ("This is test # %d. %s
", (int) i, s);

takes three (3) arguments: the format string, the integer i, and the char pointer s. So, the above printf function call needs 8 bytes for its arguments as shown below.

  3 bytes = Format String (this is treated like a generic character pointer (char *)).
  2 bytes = Integer (int i).
  3 bytes = Character Pointer (char *s).
---------
  8 bytes = Number of argument bytes

Note that the requirements and limitations placed on variable-length argument lists do not apply to reentrant functions.

Article last edited on: 2005-07-19 09:58:29

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