Keil Logo

C251: EXTENDED SCANF ARGUMENT DATA SPACE


Information in this article applies to:

  • C251 Version 3

QUESTION

I understand that the total number of bytes of arguments you can pass to a function using a variable-length argument list is limited. The limit is just 40 bytes for the LARGE memory model. That amounts to ten 4-byte arguments. I need to pass more than that to the scanf function.

In my application I must convert a very long command string that contains 16 HEX values. The sscanf invocation appears as follows:

args = sscanf(cmd_str, "%*s %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
       &cdc_cmd,
       &values[0],  &values[1],  &values[2],  &values[3],
       &values[4],  &values[5],  &values[6],  &values[7],
       &values[8],  &values[9],  &values[10], &values[11],
       &values[12], &values[13], &values[14], &values[15]);

When I compile this module I receive the following error message:

ERROR C187: 'SSCANF': SIZE OF ACTUALS EXCEEDS 'MAXARGS'

How can I overcome this problem?

ANSWER

A simple solution to your problem is to use the reentrant version of the sscanf function. You may do this by adding the #pragma function statements around the stdio.h include file. For example:

#pragma functions (reentrant)
#include        <stdio.h>               /* Standard I/O prototypes */
#pragma functions (static)

A problem with this solution is that your application may use a large amount of the hardware stack.

To avoid this, you can extend the parameter area of the static scanf function as follows:

  1. Create a new file named P_SSCANF.A51 and add it to your project.
  2. Insert the following source code into P_SCANF.A51. It adds 40 more bytes to the variable-length argument list storage area:
    ; Extended SSCANF Parameter Space
    
    $IF (LARGE)
    ?XT?sscanf      SEGMENT XDATA
                    RSEG    ?XT?sscanf
                    DS      40           ; additional 40 Bytes for Parameter
    
    $ELSE
    $IF (TINY OR SMALL)
    ?DT?sscanf      SEGMENT DATA
                    RSEG    ?DT?sscanf
                    DS      40           ; additional 40 Bytes for Parameter
    $ELSE
    ?ED?sscanf      SEGMENT EDATA
                    RSEG    ?ED?sscanf
                    DS      40           ; additional 40 Bytes for Parameter
    $ENDIF
    $ENDIF
                    END
    
  3. Specify the extended parameter with the MAXARGS directive under Options - C251 - Misc Controls. For the SMALL and TINY memory models, the initial limitation was 15 bytes. You may now specify MAXARGS(55) for these memory models. For all other memory model the initial limitation was 40 bytes. You may now specify MAXARGS(80) for these memory models.

MORE INFORMATION

Last Reviewed: Wednesday, August 3, 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.