Skip to content

Commit edcf3af

Browse files
committed
pointer add main.c
1 parent 8a5f02d commit edcf3af

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/pointer/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ set_directory_properties(PROPERTIES LABELS pointer)
22

33
add_library(pointer_fortran OBJECT lib.f90)
44

5+
add_executable(c_fortran_pointer main.c)
6+
target_link_libraries(c_fortran_pointer PRIVATE pointer_fortran)
7+
add_test(NAME C_Fortran_pointer COMMAND c_fortran_pointer)
8+
59
add_executable(cxx_fortran_pointer main.cpp)
610
target_link_libraries(cxx_fortran_pointer PRIVATE pointer_fortran)
711
add_test(NAME C++_Fortran_pointer COMMAND cxx_fortran_pointer)

src/pointer/main.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
extern void point23(float [], float [], size_t*);
5+
6+
7+
int main(void)
8+
{
9+
10+
float* a;
11+
float* b;
12+
size_t N = 3;
13+
size_t M = 2;
14+
15+
a = (float*) malloc(N * sizeof(float));
16+
b = (float*) malloc(M * sizeof(float));
17+
18+
point23(&a[0], &b[0], &N);
19+
20+
if (b[0] != a[1] || b[1] != a[2]){
21+
fprintf(stderr, "value %f != %f or %f != %f\n", b[0], a[1], b[1], a[2]);
22+
return 1;
23+
}
24+
25+
printf("OK: C to Fortran pointer\n");
26+
return 0;
27+
}

src/poly_type/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main(){
3939
add_one_C(&xtype, &x4, &A, &C);
4040
printf("C:4 = %d\n", C);
4141

42-
printf("OK: poly_type\n");
42+
printf("OK: C poly_type\n");
4343

4444
return 0;
4545
}

src/poly_type/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main(){
3939
add_one_C(&xtype, &x4, &A, &C);
4040
std::cout << "C:4 = " << C << std::endl;
4141

42-
std::cout << "OK: poly_type" << std::endl;
42+
std::cout << "OK: C++ poly_type" << std::endl;
4343

4444
return EXIT_SUCCESS;
4545
}

0 commit comments

Comments
 (0)