ARM Technical Support Knowledge Articles

EXTENDED SCANF ARGUMENT DATA SPACE

Applies to: C251 C Compiler

Answer


Information in this article applies to:


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

Article last edited on: 2005-08-03 10:20:58

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