Skip to content

Commit 8ae988d

Browse files
committed
Use dimensions correctly in declaring variables in C backend
1 parent 84bcf1c commit 8ae988d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/libasr/codegen/asr_to_c.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ std::string format_type_c(const std::string &dims, const std::string &type,
4444
const std::string &name, bool use_ref, bool /*dummy*/)
4545
{
4646
std::string fmt;
47-
std::string ref = "", ptr = "";
48-
if (dims.size() > 0) ptr = "*";
47+
std::string ref = "";
4948
if (use_ref) ref = "&";
50-
fmt = type + " " + ptr + ref + name;
49+
if( dims == "*" ) {
50+
fmt = type + " " + dims + ref + name;
51+
} else {
52+
fmt = type + " " + ref + name + dims;
53+
}
5154
return fmt;
5255
}
5356

src/libasr/codegen/asr_to_c_cpp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,11 @@ R"(#include <stdio.h>
711711
void visit_GetPointer(const ASR::GetPointer_t& x) {
712712
self().visit_expr(*x.m_arg);
713713
std::string arg_src = std::move(src);
714-
src = "&" + arg_src;
714+
std::string addr_prefix = "&";
715+
if( ASRUtils::is_array(ASRUtils::expr_type(x.m_arg)) ) {
716+
addr_prefix.clear();
717+
}
718+
src = addr_prefix + arg_src;
715719
}
716720

717721
void visit_PointerToCPtr(const ASR::PointerToCPtr_t& x) {

0 commit comments

Comments
 (0)