Change format in created C code

1 回表示 (過去 30 日間)
Luis Ruiz
Luis Ruiz 2018 年 6 月 18 日
編集済み: Walter Roberson 2018 年 12 月 27 日
I am using Matlab coder to port code to C, e.g. for the next function:
function sum_out = my_sum( x )
sum_out = 0;
for i=1:size(x,1)
sum_out = sum_out + x(i);
end
end
The generated C code is:
double my_sum(const double x[10])
{
double sum_out;
int i;
sum_out = 0.0;
for (i = 0; i < 10; i++) {
sum_out += x[i];
}
return sum_out;
}
Is there a way to make the indentation 4 spaces? Also, I would like to have the curly brackets in a separate line.

採用された回答

Ryan Livingston
Ryan Livingston 2018 年 7 月 19 日
The Coder configuration settings IndentSize and IndentStyle will let you achieve the changes you want:

その他の回答 (1 件)

upol
upol 2018 年 12 月 27 日
編集済み: Walter Roberson 2018 年 12 月 27 日
I am trying to convert this simple code into excutable using matlab coder.
function y = hello_world
%#codegen
y = 'Hello World!';
converting to source code C works but when i change the build type to Executable
It gives me this error:
Build error: C compiler produced errors. See the Build Log for further details.
C:/PROGRA~3/MATLAB/SUPPOR~1/R2018b/3P778C~1.INS/MINGW_~1.INS/bin/../lib/gcc/x86_64-w64-mingw32/6.3.0/../../../../x86_64-w64-mingw32/lib/../lib\libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
gmake: *** [C:/dummy/hello_world.exe] Error 1
The make command returned an error of 2
'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
operable program or batch file.
Error(s) encountered while building "hello_world":
### Failed to generate all binary outputs.
  1 件のコメント
Ryan Livingston
Ryan Livingston 2018 年 12 月 27 日
編集済み: Ryan Livingston 2018 年 12 月 27 日
I suggest posting new question rather than adding a question as an answer to an existing post. We frequently monitor new questions. New comments and answers may not be seen.
The linker error you see means that a C main function wasn't supplied as is required to compile an executable. The Documentation describes this in more detail with an example.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by