clinuxbashgccclang

Alias CC to refer to Clang in a shell


Are there any caveats or gotchas to aliasing cc to refer to Clang within my default shell - Z shell (presumably by editing my .zshrc file) while leaving cc aliased to gcc in another shell (Bash)?

I find Clang much easier to use mainly because it's warnings and error messages are much more readable and understandable than those of gcc. I will be enrolled in a Unix programming course next semester (purely in C) and am expected to have cleared any gcc -Wall warnings before submission of an assignment.

What I am trying to do is do most of my developing using Clang within my default shell (Z shell) using a makefile that refers to the compiler as just cc. Once satisfied I would run it once, as a test, via Bash (invoking gcc as the compiler) before submitting. The submitted makefile with cc as the compiler would then invoke gcc for the instructor, making it transparent to them. I am supposed to submit makefiles with each assignment.

I know this just seems like lazyness since I can re-edit the makefile each time, but I am trying to leave less room for error.


Solution

  • Just run

      make CC=clang
    

    or

      make CC=gcc
    

    or perhaps

      make CC='gcc -flto -Wall'
    

    (reminder: -flto should be passed at compile and at link time).