Skip to content

Commit 117760a

Browse files
committed
Dynamically allocate array
1 parent b3b0478 commit 117760a

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

tools/snippets/test/fixtures/cpp/boost/runner.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,21 @@ void generate( double *x, const unsigned int len, const char *name ) {
238238
* Main execution sequence.
239239
*/
240240
int main( void ) {
241-
double x[ 1000 ]; // TODO: tailor to fixture data
241+
double *x;
242242
int len;
243243

244-
// Henceforth, we must explicitly pass the length to internal functions:
245-
len = NUMEL( x );
244+
// Define the array length:
245+
len = 1000;
246+
247+
// Allocate an array:
248+
x = (double*) malloc( len * sizeof(double) );
246249

247250
// Generate fixture data:
248251
rand_array_f64( x, len, 0.0, 1.0 ); // TODO
249252
generate( x, len, "TODO.json" );
250253

254+
// Free allocated memory:
255+
free( x );
256+
251257
return 0;
252258
}

0 commit comments

Comments
 (0)