diff --git a/.gitignore b/.gitignore index d1515a304b..8dc78227ec 100644 --- a/.gitignore +++ b/.gitignore @@ -170,3 +170,4 @@ integration_tests/test_c_interop_01 integration_tests/test_c_interop_03 integration_tests/test_c_interop_03.c integration_tests/test_c_interop_04 +integration_tests/test_c_interop_04.c diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index fea2b23007..049bb27d63 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -156,7 +156,7 @@ RUN(NAME test_c_interop_02 LABELS cpython llvm c EXTRAFILES test_c_interop_02b.c) RUN(NAME test_c_interop_03 LABELS llvm c EXTRAFILES test_c_interop_03b.c) -RUN(NAME test_c_interop_04 LABELS llvm +RUN(NAME test_c_interop_04 LABELS llvm c EXTRAFILES test_c_interop_04b.c) RUN(NAME test_c_interop_05 LABELS llvm EXTRAFILES test_c_interop_05b.c) diff --git a/src/libasr/codegen/asr_to_c.cpp b/src/libasr/codegen/asr_to_c.cpp index b6308f6174..23cf10d711 100644 --- a/src/libasr/codegen/asr_to_c.cpp +++ b/src/libasr/codegen/asr_to_c.cpp @@ -44,10 +44,13 @@ std::string format_type_c(const std::string &dims, const std::string &type, const std::string &name, bool use_ref, bool /*dummy*/) { std::string fmt; - std::string ref = "", ptr = ""; - if (dims.size() > 0) ptr = "*"; + std::string ref = ""; if (use_ref) ref = "&"; - fmt = type + " " + ptr + ref + name; + if( dims == "*" ) { + fmt = type + " " + dims + ref + name; + } else { + fmt = type + " " + ref + name + dims; + } return fmt; } diff --git a/src/libasr/codegen/asr_to_c_cpp.h b/src/libasr/codegen/asr_to_c_cpp.h index 8575f1b2da..f0fa6dacc3 100644 --- a/src/libasr/codegen/asr_to_c_cpp.h +++ b/src/libasr/codegen/asr_to_c_cpp.h @@ -711,7 +711,11 @@ R"(#include void visit_GetPointer(const ASR::GetPointer_t& x) { self().visit_expr(*x.m_arg); std::string arg_src = std::move(src); - src = "&" + arg_src; + std::string addr_prefix = "&"; + if( ASRUtils::is_array(ASRUtils::expr_type(x.m_arg)) ) { + addr_prefix.clear(); + } + src = addr_prefix + arg_src; } void visit_PointerToCPtr(const ASR::PointerToCPtr_t& x) {