Issue
Let's say we have a simple c++ file named hello.cpp
which prints "Hello World!".
We generally create the executable using g++ hello.cpp
. When I tried executing the command c++ hello.cpp
it creates the executable successfully. Shouldn't it throw an error saying there is no c++ command available? and suggest us to use g++?
I tried running man c++
on the terminal, this brings up the GNU C Project page. So, does the terminal replace our c++ hello.cpp
with g++ hello.cpp
internally? It shouldn't do that right?
Additional Info:
Similarly, if I have a hello.c
program that prints "Hello World!". When I execute c hello.c
on the command line, I get the error:
$ c hello.c
c: command not found
This is expected since we have to use gcc hello.c
. Why am not getting a similar error for the c++ hello.cpp
?
Solution
Shouldn't it throw an error saying there is no c++ command available? and suggest us to use g++?
Weeelll, there are no regulations or standards that restrict or require c++
command to do anything, so there is no "should" or "shouldn't". However, it would be strongly expected that c++
is a working C++ compatible compiler, that supports similar or same flags as cc
does.
does the terminal replace our c++ hello.cpp with g++ hello.cpp internally?
A terminal is the device that displays things. Terminal does not replace it, it has no effect on it.
Most probably your system designer, but maybe administrator or publisher or distributor or package designer (or anyone in the chain), configured your system to provide a command named c++
. Usually, that command is a symbolic link to a working C++ compiler, usually g++ on Linux systems. On my system, /usr/bin/c++
program is just installed with package named gcc
, but some systems allow it to be configurable.
It shouldn't do that right?
As stated above, terminal shouldn't replace commands, it has no effect on it.
This is expected since
It is expected since there is no command named c
. There are endless other unknown commands.
cc
is the good old name for a C compiler. c99
is the standardized name of C99 compatible compiler.
Why am not getting a similar error for the c++ hello.cpp?
Because a command named c++
exists on your system.
Answered By - KamilCuk