Logo

Programming-Idioms

History of Idiom 190 > diff from v8 to v9

Edit summary for version 9 by abdec:
[C] Secure Coding: Instead of hard coding the count, it should be calculated to avoid later mistakes with changed a[]!

Version 8

2020-12-11, 05:26:57

Version 9

2021-08-16, 06:00:00

Idiom #190 Call an external C function

Declare an external C function with the prototype

void foo(double *a, int n);

and call it, passing an array (or a list) of size 10 to a and 10 to n.

Use only standard features of your language.

Idiom #190 Call an external C function

Declare an external C function with the prototype

void foo(double *a, int n);

and call it, passing an array (or a list) of size 10 to a and 10 to n.

Use only standard features of your language.

Variables
a,n
Variables
a,n
Extra Keywords
C interoperability
Extra Keywords
C interoperability
Code
void foo(double *a, int n);
double a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
foo (a, 10);
Code
void foo(double *a, int n);
double a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
foo (a, sizeof(a)/sizeof(*a));
Comments bubble
Instead of hard coding the count, it should be calculated to avoid later mistakes with changed a[]!