Skip to content

Commit 01f42f6

Browse files
committed
add c malloc
1 parent 77d216d commit 01f42f6

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/malloc/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
set_directory_properties(PROPERTIES LABELS malloc)
22

3+
add_executable(c_fortran_malloc main.c)
4+
set_target_properties(c_fortran_malloc PROPERTIES LINKER_LANGUAGE C)
5+
target_link_libraries(c_fortran_malloc PRIVATE vector_fortran)
6+
add_test(NAME C_Fortran_malloc COMMAND c_fortran_malloc)
7+
38
add_executable(cxx_fortran_malloc main.cpp)
49
target_link_libraries(cxx_fortran_malloc PRIVATE vector_fortran)
510
add_test(NAME C++_Fortran_malloc COMMAND cxx_fortran_malloc)

src/malloc/main.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
extern void timestwo(int [], int [], const size_t*);
5+
6+
7+
int main()
8+
{
9+
const size_t N = 3;
10+
11+
int* x = malloc(N*sizeof(int));
12+
int* x2 = malloc(N*sizeof(int));
13+
14+
timestwo(&x[0], &x2[0], &N);
15+
16+
for (size_t i=0; i < N; i++){
17+
if (x2[i] != 2*x[i]){
18+
fprintf(stderr, "value %d != %d\n", x2[i], x[i]);
19+
return 1;
20+
}
21+
}
22+
23+
free(x);
24+
free(x2);
25+
26+
printf("OK: C malloc new\n");
27+
28+
return 0;
29+
}

0 commit comments

Comments
 (0)