Compare C code online

A short C program where the variables, the threshold and the messages changed. Load your own .c or .h files to compare them. Tips for C

Original
0 lines
Drop to load into original
Changed
0 lines
Drop to load into changed
−0+0
Original
Changed

About this C comparison

In C, a changed constant or a renamed variable can be the difference between a working build and a subtle bug. Comparing the two versions of a source file shows each changed statement and marks the identifiers and literals that differ.

It is handy for reviewing a patch before you apply it, checking a student submission against a reference solution, or seeing what changed between two releases of a header.

What changed in this sample

  • The variables a, b and sum became x, y and result, with new values 12 and 18.
  • The printf label changed from “Sum” to “Result”.
  • The threshold in the if moved from 15 to 20, and both messages were updated to match.

Tips for comparing C

Compare headers and sources
Open a .h or .c file and C highlighting is picked automatically. Drop two files at once to fill both sides.
Brace style changes
If one file was reformatted with clang-format, turn on Ignore whitespace and Ignore blank lines to see only the code that changed.
Line endings
Code from Windows and Linux machines often differs only in CRLF versus LF. Line endings are never counted as changes, and you are told when they differ.
Export a patch
Download .diff file gives a unified diff you can apply with patch or git apply.

How to compare C online

  1. Paste the older version into Original and the newer one into Changed, or open a file on each side.
  2. Check that the syntax menu says C, then pick split or unified view.
  3. Step through the changes with the arrows or Alt ↓, and use Settings for options such as ignoring blank lines.
  4. Save the comparison in your browser, share a link, or download it as a .diff, HTML or PDF.

C comparison: questions

Can I compare two versions of a C file without git?

Yes. Paste or open both versions here and you get the same line-by-line view a git diff gives, plus word-level marks, without any repository.

Does it compile or check the code?

No. It only compares the text. Nothing is compiled or executed.

Can I compare preprocessor-heavy code?

Yes. Macros and #ifdef blocks are compared as text like any other line, and they are highlighted with C syntax colours.