svn - GCC branches vs Subversion and Git - Stack Overflow
c++ - What is the difference between g++ and gcc? - Stack Overflow
GCC or Clang
GitHub - hanoglu/TermiC: GCC powered interactive C/C++ terminal created with BASH
Pretty cool stuff. The usage of output to decide whether something is to be kept is a pretty clever one, keeping things simple, while allowing functions and structs. (It would be really nice, if they could be replaced, but probably not worth it).
Some ideas for the script (even if this is C, not (ba)sh subreddit)
-
sh's
casesupports string matching (unlike C'sselect) -
cmd && x=true; if $xcan be written simply asif cmd -
mktemp on *BSD and MacOS expect (at least according to documentation) the X's to be at the end
-
echo "\cat $sourceFile`"can be simplified to justcat $sourceFile` -
a here-doc could be more readable for the initial header
-
hey, a real C comment: using
""(instead of<>) for standard includes is semantically wrong -
two strings can be joined by a newline with:
"$str1"$'\n'"$str2", no need to use echos and backticks -
string literals probably mustn't include (unbalanced) curly braces, but not sure it makes sense to add complexity to handle that case
-
I like the
yes ... | headtrick, but I'd use| tr -d '\n'instead of running echo
Anyway, the idea is great, and the implementation looks like it works. Will probably try it out at some point; wouldn't leave all those test.cs and asdf.cs lying around everywhere. Thanks!
(Sorry for the earlier noise, my pocket's LLM is not very good).
More on reddit.comgcc and g++ are compiler-drivers of the GNU Compiler Collection (which was once upon a time just the GNU C Compiler).
Even though they automatically determine which backends (cc1 cc1plus ...) to call depending on the file-type, unless overridden with -x language, they have some differences.
The probably most important difference in their defaults is which libraries they link against automatically.
According to GCC's online documentation link options and how g++ is invoked, g++ is roughly equivalent to gcc -xc++ -lstdc++ -shared-libgcc (the 1st is a compiler option, the 2nd two are linker options). This can be checked by running both with the -v option (it displays the backend toolchain commands being run).
By default (and unlike gcc), g++ also adds linker option -lm -- to link against libm which contains implementations for math.h.
GCC: GNU Compiler Collection
- Referrers to all the different languages that are supported by the GNU compiler.
gcc: GNU C Compiler
g++: GNU C++ Compiler
The main differences:
gccwill compile:*.c\*.cppfiles as C and C++ respectively.g++will compile:*.c\*.cppfiles but they will all be treated as C++ files.- Also if you use
g++to link the object files it automatically links in the std C++ libraries (gccdoes not do this). gcccompiling C files has fewer predefined macros.gcccompiling*.cppandg++compiling*.c\*.cppfiles has a few extra macros.
Extra Macros when compiling *.cpp files:
#define __GXX_WEAK__ 1
#define __cplusplus 1
#define __DEPRECATED 1
#define __GNUG__ 4
#define __EXCEPTIONS 1
#define __private_extern__ extern
I primarily program on Linux and have always used GCC, but have recently been interested in switching over to using Clang. It seems like the runtime performance of the two compilers is similar, but I am also interested in C standards compliance going into the future, as well as things like error messaging, memory-leak checking, etc.
If anyone here is knowledgeable about compilers and the differences or advantages of one or the other, I'd like to hear your opinion.