views:

1694

answers:

8

I am aware that on most GNU/Linux systems, GCC can be invoked by the name "cc" from the command line (as opposed to "gcc"). What I am wondering is if there is any difference in GCC's behavior when it is invoked one way versus the other.

For example, I know that invoking GCC through the name "g++" instead of "gcc" causes GCC to behave differently (it treats .c files as C++ source and links-in the C++ standard library). Is there any similar difference in behavior between "gcc" versus "cc"?

EDIT: None of the answers received so far gave a definitive "yes" or "no" as to whether GCC will behave differently if invoked one way versus the other. However, the idea given to dive into the source to check it's behavior lead me down that path. Based upon what I found there, I now believe that the answer is:

No. GCC behaves the same regardless of whether it is called via "gcc" or "cc".

+6  A: 

On my mac from man gcc:

In Apple's version of GCC, both cc and gcc are actually symbolic links to a compiler named like gcc-version. Similarly, c++ and g++ are links to a compiler named like g++-version.

Based on that I would assume that cc and gcc behave the same way.

stefanB
it's common on Unix world to set several links to the same executable, and it changes some defaults according to the name it was used when called.
Javier
woah and a downvote without explanation - very helpful ... maybe they didn't like something?
stefanB
perhaps an Apple hater? :)
Dan Moulding
Maybe they don't know that Mac OS X is fully posix compliant Unix system
stefanB
No, perhaps they consider confusing the following logical chain: "symlinked to the same executable -> same behavior". For instance all your basic command line utils can be symlinked to busybox on minimal system, yet function as entirely separate utils
EFraim
A: 

Considering this is coming from UNIX, I'd say that "cc" is the generic name and "gcc" is the actual compiler. i.e. "gcc" provides "cc" so a program looking for "cc" would find and use "cc", blissfully ignorant of the actual compiler being used.

Also, UNIX programs should be ignorant of the actual name used to call them (think Windows Desktop shortcuts -- it doesn't make sense to check what the shortcut was called), so, no, "gcc" and "cc" do the same thing if "cc" is a link to "gcc".

Unless, of course, "cc" is not a symlink but a shellscript calling gcc.

Alan
gzip checks its name. If its name is gunzip it assumes -d.
Joshua
"Also, UNIX programs should be ignorant of the actual name used to call them" It's absolutely not true. Have you ever heard of multi-call binaries? I.e. Busybox? http://www.busybox.net/
mateusza
and, after all, "sh" is usually a symlink to "bash", which makes it behave as a POSIX shell. sh<->bash is actually very similar to cc<->gcc .
Johannes Schaub - litb
Well, gzip<->gunzip is a case of the same utility providing two different utilities. In the case of gcc<->cc it's providing one thing.I did make a generalisation about unix tools being argv[0] agnostic, but for the most part they are, simply because otherwise they'd break if renamed. If one binary provides more than one utility, then, yes, there's a difference between calling it directly and calling the symlink it creates to provide the tool in question, but gcc<->cc is not that: unless the semantics (i.e. expected behaviour) change, they're synonyms for historical reasons.
Alan
+7  A: 

It looks to me that cc (link to some old SUS specification) is intended to be the vendor-neutral interface to the system's compiler. It's marked as legacy:

The c89 utility provides an interface to the ISO C standard, but the cc utility accepts an unspecified dialect of the C language: it may be Standard C, common-usage C or some other variant. Portable C programs should be written to conform to the ISO C standard and compiled with c89.

POSIX has a utility called c99 which i believe is the successor of c89. It says

The c99 utility is based on the c89 utility originally introduced in the ISO POSIX-2:1993 standard.

Some of the changes from c89 include the modification to the contents of the Standard Libraries section to account for new headers and options; for example, added to the -l rt operand, and the -l trace operand added for the Tracing functions.

I'm not really familiar to all those different Standards, but it looks like the more recent SUSv3 (Posix 2004) and the yet more recent Posix2008 (doesn't seem to have a SUS number yet) do not specify a utility called cc anymore, but only the utility called c99. Incidentally, my linux system (archlinux) contains a manpage of c99 but not c89, but only contains a utility called cc, but neither c89 nor c99. Much confusion in there :)

Johannes Schaub - litb
Interesting link. Someone should probably tell the GNU Make people about this, because it will still invoke "cc" as the default if you don't override ${CC}. Apparently they should be using one of the other utilities as a default. It would seem that c89 *should* be the preferred utility according to the standard.
Dan Moulding
OTOH, since that was written in 1997, maybe these days the preferred utility ought to be c99.
Dan Moulding
yes, SUSv3 doesn't include c89 anymore. only the old one i linked to recommended it (SUSv2)
Johannes Schaub - litb
+1  A: 

cc is just the UNIX way of calling the compiler, it will work on all Unices.

cartman
This does not address the question.
bortzmeyer
Actually it does, cc means "C compiler" on Unix, nothing more.
cartman
The questioner asked about the difference of cc and gcc too. This serves as an answer too and addresses the question, imo
Johannes Schaub - litb
+1  A: 

Nothing in the gcc documentation indicates that gcc would behave any differently if it's executable name is not gcc but cc. The GNU Fortran compiler even mentions that:

A version of the gcc command (which also might be installed as the system's cc command)

lothar
+13  A: 

For grins, I just traced down how argv[0] is used from within gcc (main.c -> top_lev.c -> opts.c -> langhooks.c) and it appears that argv[0] is currently used for nothing more than giving malloc something to report when it fails. There doesn't appear to be any behavior change if argv[0] is anything other than gcc.

plinth
The only problem that I have with that is that "cc --version" gives *slightly* different output from "gcc --version" (it says "cc" instead of "gcc"). So *something* in there must be looking at argv[0].
Dan Moulding
Your answer motivated me to look into the source code myself. I found that argv[0] does get assigned to "programname" which ends up getting passed around a bit to other functions (and gets stored in the environment). Although I didn't do an *exhaustive* search, from what I can see, it is only ever used for display purposes (e.g. in the "--version" output, "usage" output, error messages, etc).
Dan Moulding
A: 

I've been using UNIX since 1983, and the C compiler back then was called cc. Irt's nice to think that maybe a makefile I wrote back then could still work on the latest Linux distro today...

anon
Well, the reason this came up is actually because GNU Make defaults the ${CC} variable to just "cc" rather than "gcc" (for historical reasons, I'm sure). So if you use the default built-in rules of GNU Make, it will compile using "cc". I was wondering if it makes any difference if I reassign ${CC} to "gcc" versus just leaving it alone.
Dan Moulding
You should only change it if your using GCC specific features that way, it will fail to compile straight off on machines without GCC.
Joe D
A: 

Although the question has been asnwered, but I had the same doubt today and i tried to find on my own:

$ which cc
 /usr/bin/cc
$file /usr/bin/cc
 /usr/bin/cc: symbolic link to '/etc/alternatives/cc'
$file /etc/alternatives/cc
 /etc/alternatives/cc: symbolic link to '/usr/bin/gcc'
$which gcc
 /usr/bin/gcc
So, basically cc points to gcc.
You could also check using cc -v and gcc -v
If they print out the same thing, that means they are exactly the same.

N 1.1