gpt4 book ai didi

linux - 如何使用 diff 到 C++ 源文件并忽略行空间和注释

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:59:30 24 4
gpt4 key购买 nike

我必须要 C++ 源文件,我想看看这两个文件之间的区别。但我不想看到评论之间的差异。

请指教。

非常感谢。

最佳答案

一种方法是使用预处理器删除注释并使用 process substitution 将其传递到 diff 中...

diff -uwB <(g++ -E left.cpp) <(g++ -E right.cpp)

当然,这会拉入您#include 的文件并扩展您的#define 宏。如果它们没有改变,这应该是非常可读的。

我传递给 diff 的开关是:

-w  --ignore-all-space  Ignore all white space.
-B --ignore-blank-lines Ignore changes whose lines are all blank.
-u -U NUM --unified[=NUM] Output NUM (default 3) lines of unified context.

关于linux - 如何使用 diff 到 C++ 源文件并忽略行空间和注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9169588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com