.C as a file extension for C++ is not portable
nibblestew.blogspot.com
nibblestew.blogspot.com
So if you care about your project being able to be checked out on Windows, please refrain from using .C extension for C++ files. I've seen a toy language repo that used "something.s" for the test source file and "something.S" for the part of the language runtime (or something like this, don't quite remember), and checking it out on Windows was great fun: git declares that the working directory at the same time is both dirty and has no changes in files.
Only if you use -save-temps, which is rarely used (it's there mostly for when you want to debug the preprocessed code). Otherwise, in the common case where you are going from the .S to the .o, the intermediate .s is saved somewhere in /tmp (without -pipe) or exists only in memory (with -pipe).
Have you ever seen a Windows program that to tries to create "etc" directory in the C:'s root and put its config files there? I've seen, and it was "ported" from Linux.
This is just my prejudice, I haven't actually checked, but I think most projects that have support for both Linux (or Unix-y OSes) and Windows generally start with Linux/Unix and then have Windows support added. I think the opposite is rare.
Maybe things changed? I think most Windows developers say 10 or 15 years ago might not even know what Linux is, or have heard the word as some obscure technology used by few. In other words, I would have expected a Windows developer to respond to "doesn't compile on Linux" the same as they would for e.g. "doesn't compile on Plan 9", or whatever is still very obscure relative to Windows nowadays.
Also, there is this gem[3]:
> I still run into modules that try to create temporary files in the root directory of my C: drive. That usually happens due to the script clearing the environment and not saving temporary directory locations. This is an unfortunate interaction with File::Spec->tmpdir which defaults to trying to write to the root (hey, Windows 95 allowed it!) of the current drive if it can’t locate the customary directories. I think File::Spec->tmpdir ought to croak if the environment does not contain one of TMP, TEMP, or TMPDIR, instead of offering C:\system\temp or C:\temp or /tmp or / on Windows. Regardless of File::Spec’s behavior, scripts, modules, etc should not delete those environment variables.
[1]: https://www.nu42.com/2014/12/yeah-you-put-me-in-my-place-rea...
[2]: https://www.nu42.com/2014/11/fixing-hard-coded-file-path-in-...
[3]: https://www.nu42.com/2018/03/dont-complicate-things.html
[1] https://en.wikipedia.org/wiki/Common_Desktop_Environment
Anyway I would never rely on the C compiler invoking the C++ compiler; I always write g++ or $CXX. I wonder if there is a downside to that.
Historically, though, lowercase character weren’t allowed in file names (even though the on-disk format would have allowed it), so compilers couldn’t make the distinction. Given that using “.C” has fallen out of fashion (if it ever was fashionable), I don’t see much pressure to add that functionality, especially given that it might break compilation of C source code copied over from old times that uses .C.
I have seen .cc for C++ and it annoys me, but seems rather common.
Nobody thinks that. Everybody knows what it means. Picking on it is like picking on people referring to amd64 as x86.
I'd happily apply for a "C/Rust" job as well.
No[1]:
> C++ source files conventionally use one of the suffixes `.C`, `.cc`, `.cpp`, `.CPP`, `.c++`, `.cp`, or `.cxx`; C++ header files often use `.hh`, `.hpp`, `.H`, or (for shared template code) `.tcc`; and preprocessed C++ files use the suffix `.ii`. GCC recognizes files with these names and compiles them as C++ programs even if you call the compiler the same way as for compiling C programs (usually with the name gcc).
[1] https://gcc.gnu.org/onlinedocs/gcc/Invoking-G_002b_002b.html
So to make the implied answer to the question explicit: no, it's because someone who knew the difference between C and C++ sought to distinguish between their source code files using a filename extension convention that becomes invisible on a different OS.
Not even close. C++ is a vastly more complex language with a very different philosophy from that of C.
You might argue that C can very roughly be treated as a subset of C++, but this really is a very rough approximation. Which is to say, really, that it's wrong.
> And they inter-link
It's generally very easy to call C code from C++ code, yes. It is not easy to call C++ code from C.
Well, 99% of the time this holds, and you can generally use the same tooling in different modes for both. And they share a preprocessor.
> It's generally very easy to call C code from C++ code, yes. It is not easy to call C++ code from C.
Significantly easier than almost any other pair of languages, though. Especially if you take a little care on the C++ side (extern "C") or use COM or similar.
Again, C is more compatible with C++ than python 2 is with python 3. But not the other way round.
> Significantly easier than almost any other pair of languages, though.
I wouldn't say so. If you're using the features of C++ then you'd need to manually wrap it all to expose a C API.
Accessing C code from C++, Ada, Rust, Zig, Java, Python, C#, or just about any other language, would be easier than manually wrapping C++ to expose a C API.
(The LLVM compiler, written in C++, does this. It exposes a subset of its API as a C API. I get the impression it's no small task, or they'd expose the full LLVM library that way.)
> Especially if you take a little care on the C++ side (extern "C") or use COM or similar.
Agreed, but going the extern "C" route implies you're using C++ as a better C, rather than making full use of C++. I have to admit I don't know much about working with COM. It's vaguely like GObject, right? I imagine it must take quite a bit of work to expose a C++ API that way.
Well, MSVC compiles .c files as C, which I guess makes it also a C compiler? It supports most of C99 by now.
> MSVC doesn't officially support C to this day.
Oh, it does: https://docs.microsoft.com/en-us/cpp/build/walkthrough-compi...
That being said, there are indeed projects using lowercase .c extension for their "C++" file: gdb [1][2]
[1] https://github.com/bminor/binutils-gdb/blob/3e5fac07975a310c... [2] https://github.com/bminor/binutils-gdb/blob/master/gdbsuppor...
The use of .c for a C++ file is probably a project that decided, decades later, to switch from C to C++ and didn't want to go through the hassle of renaming all of their source code files to reflect the language switch.
Here’s an article about it: https://www.howtogeek.com/354220/how-to-enable-case-sensitiv...
Flipping that setting might make the file system case sensitive, but those Windows applications would still be working as if they were running in a case insensitive world.
For example lets imagine some sort of batch processing application that runs user defined scripts.
To define some batch process, the user provides the name the script to be run, so they enter 'MyScript.py' even though the file lives on disk as the 'myscript.py' file.
That batch processing application then saves the user supplied file name 'as is' and everything works fine in default Windows file system mode.
However, flipping that file system option to make it case sensitive suddenly the batch processing will fail.
As Windows applications don't have to deal with case sensitivity, they don't do things like check if the user has entered the name correctly in terms of case.
The just ask the file system if the file exists and likewise, Windows is not checking the case when it does that 'exists' check.
I haven’t tried it, but I would assume that’s exactly what happens. The file system, with the case-sensitive flag, should return "File does not exist".
That’s probably also the reason why there is no direct way to enables case-sensitivity recursively ;)
[0]: https://superuser.com/questions/266110/how-do-you-make-windo...
Before XP flag 1 meant case-sensitive, now it means case-preservant and flag 2 handles case-sensitive search.
Stackoverflow talks about NFS and something completely different.
Normalization should be done in the file manager or in a gui file picker, and not at the filesystem level.
Ideally for the cmake tool, the filename should not have anything but lowercase letters too.
Why shouldn't it be?
Edit: morning brain fart. Actually, I guess "+" is not all that special.
My recollection is that the first Unix C compilers (Cfront?) used ".cc" for c++ and Microsoft started using ".cpp" , probably because of the above restriction.