|ARM Technical Support Knowledge Articles|
Applies to: C51 C Compiler
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?
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
Did you find this article helpful? Yes No
How can we improve this article?