1/* 2 * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230) 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <assert.h> 8#include <camkes.h> 9#include <stdio.h> 10#include <stddef.h> 11#include <stdlib.h> 12 13int run(void) { 14 int operands[] = { 342, 74, 283, }; 15 int *inplace; 16 int *other; 17 size_t operands_sz = sizeof(operands) / sizeof(int); 18 size_t other_sz; 19 size_t inplace_sz = 2; 20 const char *name = get_instance_name(); 21 22 inplace = (int*)malloc(sizeof(int) * inplace_sz); 23 assert(inplace != NULL); 24 inplace[0] = 7; 25 inplace[1] = 8; 26 27 printf("%s: what's the answer to ", name); 28 for (int i = 0; i < operands_sz; i++) { 29 printf("%d ", operands[i]); 30 if (i != operands_sz - 1) { 31 printf("* "); 32 } 33 } 34 printf("\n"); 35 printf("%s: and ", name); 36 for (int i = 0; i < inplace_sz; i++) { 37 printf("%d ", inplace[i]); 38 if (i != inplace_sz - 1) { 39 printf("* "); 40 } 41 } 42 printf("\n"); 43 44 int answer = a_calculate(operands_sz, operands, &other_sz, &other, &inplace_sz, &inplace); 45 46 printf("%s: first result was %d\n", name, answer); 47 printf("%s: second result was %d (len that should have been 1 was %d)\n", name, inplace[0], inplace_sz); 48 printf("%s: other is {", name); 49 for (int i = 0; i < other_sz; i++) { 50 printf("%d, ", other[i]); 51 } 52 printf("}\n"); 53 return 0; 54} 55