Best practices for MATLAB code
Does exist in MATLAB code some directive like C #ifdef
#ifdef name
program text
#else
more program text
#endif
or just I use if instruction?
Thanks,
F.

댓글 수: 2

dpb
dpb 2026년 4월 12일 21:37
To add, MATLAB does not implement any preprocessor directives, no.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2026년 4월 12일 21:44

0 개 추천

There is no equivalent to the C preprocessor in MATLAB.
The C pre-processor can do some ugly things, such as
#ifdef __CPLUS
void strlen (
#else
if (fiddlesticks) {
#endif
that can completely change the meaning of the code
There is no MATLAB equivalent of that.
The closest you can get is to use something like
if exist('name', 'var')
but you cannot achive the wholesale corruption of the code the way you can in C or C++.

댓글 수: 2

fabrizio restori
fabrizio restori 2026년 4월 12일 22:31
Grazie
dpb
dpb 2026년 4월 13일 12:22
편집: dpb 2026년 4월 14일 15:33
"... you cannot achi[e]ve the wholesale corruption of the code ..."
Not to worry....you can still create mass confusion with intentional or accidental silent aliasing of MATLAB builtins... <grin>

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

태그

질문:

2026년 4월 12일 19:12

편집:

dpb
2026년 4월 14일 15:33

Community Treasure Hunt

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

Start Hunting!

Translated by