File: args.c

package info (click to toggle)
sdcc 3.8.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 99,212 kB
  • sloc: ansic: 918,594; cpp: 69,526; makefile: 56,790; sh: 29,616; asm: 12,364; perl: 12,136; yacc: 7,179; lisp: 1,672; python: 812; lex: 773; awk: 495; sed: 89
file content (45 lines) | stat: -rw-r--r-- 990 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/** Tests argument passing to functions.
    Assumes that up to the first two arguments can be passed in registers.

    type1: char, int, long
    type2: char, int, long
    type3: char, int, long
 */
#include <testfwk.h>

static {type1}
returnFirstArg({type1} arg1, {type2} arg2, {type3} arg3)
{
    UNUSED(arg2);
    UNUSED(arg3);
    return arg1;
}

static {type2}
returnSecondArg({type1} arg1, {type2} arg2, {type3} arg3)
{
    UNUSED(arg1);
    UNUSED(arg3);
    return arg2;
}

static {type3}
returnThirdArg({type1} arg1, {type2} arg2, {type3} arg3)
{
    UNUSED(arg1);
    UNUSED(arg2);
    return arg3;
}

static void
testArgs(void)
{
    ASSERT(returnFirstArg(123, 45, 67) == ({type1})123);
    ASSERT(returnFirstArg(-123, 45, 67) == ({type1})-123);

    ASSERT(returnSecondArg(1, -23, 64) == ({type2})-23);
    ASSERT(returnSecondArg(1, 8, 64) == ({type2})8);

    ASSERT(returnThirdArg(-33, -34, -35) == ({type3})-35);
    ASSERT(returnThirdArg(-33, -34, 35) == ({type3})35);
}