Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is clang used for autocompletion in vim and emacs?

Why isn't gcc used for that? Where is the difference between them and why does almost any autocomplete plugin require clang?

like image 639
Kristaps Čivkulis Avatar asked Nov 20 '22 02:11

Kristaps Čivkulis


1 Answers

The simple answer is that clang was designed to support completion while gcc was not.

Clang has a command line option that prints out possible completions at a given point in a source file, which makes it easy to use in scripts: Just shell out to clang, parse its output, done. Gcc has nothing comparable.

As for why, see this list of differences between gcc and clang:

[...]

  • Clang is designed as an API from its inception, allowing it to be reused by source analysis tools, refactoring, IDEs (etc) as well as for code generation. GCC is built as a monolithic static compiler, which makes it extremely difficult to use as an API and integrate into other tools. Further, its historic design and current policy makes it difficult to decouple the front-end from the rest of the compiler.
like image 192
melpomene Avatar answered Nov 22 '22 15:11

melpomene