On 06/01/10 09:55, Gusman wrote:
Dear All,
Currently I'am working with a big source code in C language which have
many #ifdef directives in there. It's so difficult for me to read the
code flow while I can't determine which #ifdef is defined or not defined.
Is there plugin can make undefined #ifdef code block same as #if 0 code
block.
Thank you in advance.
Best Regards,
Gusman Dharma P
I don't think there is a foolproof way to do this (unless... see last
paragraph), because of all the places where macros can be defined (the
concrete examples below apply to gcc, but most compilers have similar
mechanisms):
- in the source of the same file, before they are used (the easiest)
- in included "files"
- in included <files>, whose location is found by searching all
directories listed in -I switches on the compiler's command-line
- by -D switches on the compiler command-line
- for predefined compiler-specific macros, they don't need a definition
This means that the identical same source file can be compiled twice
with different "true" and "false" #if regions, with absolutely no
changes to the source file itself. For instance whenever there are
patches to the C source, I compile two versions from the same Makefile:
one version has its sources in .build/vim/vim72/src/, the other's
sources, in .build/vim/vim72/src/tiny/, are (every single one of them)
softlinks to files of the same name in the parent directory.
Quite a number of the defines are set in auto/config.h which is
different between both; but several are also defined (especially for the
Huge version) on the compiler command-line.
When reading the Vim source, I can look ahead and behind for #if / #else
/ #endif blocks, and maybe use cscope to find where (if anywhere) the
name is defined (which may be in an include file which is not part of
the Vim distribution), but I think that the task of determining which
macros are defined (and with which value if any) at which point in the
source is a task for a source preprocessor (including the "preprocess"
phase of a multistep compiler such as gcc), not for an editor.
One way to get it though (I think) would be (if your compiler allows it)
to run only the preprocessor step, with the exact same implicit and
explicit defines as for a "real" compile, and examine the output of that
preprocess, where, I suppose, all macros would be resolved, and "false
#if blocks" removed.
Best regards,
Tony.
--
"I have seen the future and it is just like the present, only longer."
-- Kehlog Albran, "The Profit"
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php