I am looking for an application that can compare two C++ sources and find the code-meaningful differences (to compare versions which may have been reformatted differently). At the very minimum, something which has the capability for ignoring changes in white spaces, tab spaces and newlines which do not affect the functionality of the source (note that whether a newline is considered whitespace is language-dependent, and C and C++ do so). And, ideally, something that can identify exactly all code-meaningful differences. I am under Ubuntu.
As per diff --help | grep ignore
, I expected diff -bBwZ
to do reasonably the job (I expected to get some false negatives, to be dealt with later).
Nevertheless, it doesn't.
if I have the following files with snippets
test_diff1.txt
else if (prop == "P1") { return 0; }
and test_diff2.txt
else if (prop == "P1") {
return 0;
}
then
$ diff -bBwZ test_diff1.txt test_diff2.txt
1c1,3
< else if (prop == "P1") { return 0; }
---
> else if (prop == "P1") {
> return 0;
> }
instead of empty results.
Using a code formatter as a "filter" on both inputs may filter out these differences, but then the resulting output would have to be tied back to the original inputs for the final reporting of differences to keep actual text and line numbers. So the objective is attainable without a need for a compiler properly... I do not know if something is available, though.
Can the objective be attained with diff
?
Otherwise, is there an alternative (preferably, for command line)?