Keil Logo



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. MAXARGS has no influence on library functions which are using variable argument lists (example: printf, scanf...).

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\n", (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.


  • Refer to MAXARGS in the Cx51 User's Guide.


Last Reviewed: Tuesday, November 6, 2012

Did this article provide the answer you needed?
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.