7 ms·
.C as a file extension for C++ is not portable
- Ballas 6y agoIs that something people do? I have never seen a C++ file with a .c extension. I have seen plenty of C++ headers with .h extension, though.
- hvdijk 6y agoThis is about C++ files with a .C extension, not a .c extension.
- rfoo 6y agoI think it meant uppercase .C instead of lowercase .c as a C++ extension. Indeed it's pretty rare. 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/3e5fac07975a310c90772e59c17955b4137cc49b/gdb/macroscope.c#L38 https://github.com/bminor/binutils-gdb/blob/3e5fac07975a310c... [2] https://github.com/bminor/binutils-gdb/blob/master/gdbsupport/gdb_unique_ptr.h#L47:28 https://github.com/bminor/binutils-gdb/blob/master/gdbsuppor...
- Ballas 6y agoI see, thanks for clearing that up. (I have obviously also not seen the uppercase .C used before.)
- jcranmer 6y agogcc does as well. 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.
- bit-hack 6y agoI've honestly never seen .C used in the wild. I imagine anyone whose written a bit of portable code would immediately realize this is a bad idea.
- kwk1 6y agoJust for an example, the OpenFOAM codebase has 'em.
- captainmuon 6y agoI only know it as an extension for "interpreted C++ scripts" as used by CERN's ROOT. It is considered good practice to make them compilable but the interpreter used to be very lenient (before they integrated it with clang) so that usually didn't happen. 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.
- jsrcout 6y agoHaven't really seen it in the wild, but I see it every day in a very large proprietary codebase I work in.
- jagged-chisel 6y agoIs this something that happens because someone thinks C/C++ is one language? I often see this single mythical language referred to in job postings, blog posts from folks with a range of experience in the field, and even in neophytes who got terrible information from their Java instructor at university. But I don't think I've ever come across it in an actual codebase. I have seen .cc for C++ and it annoys me, but seems rather common.
- yakubin 6y ago> Is this something that happens because someone thinks C/C++ is one language? Nobody thinks that. Everybody knows what it means. Picking on it is like picking on people referring to amd64 as x86.
- borodi 6y agoPeople think that. amd64 and x86 today mean the same thing, C and C++ not quite. I've also seen HR people think that java and javascript are the same thing.
- pdpi 6y agoOutside the world of people who do write C or C++, most people I talk to really do bucket the two together as if they were largely interchangeable or, at least, a lot more similar than they actually are.
- adrianmsmith 6y agoRight I mean one project I was working on who had to write some JavaScript and would always refer to that language as Java. He was a developer, literally using one of the languages, so should have known better. And Java and JavaScript have less in common than C and C++.
- yakubin 6y agoBucketing them together is fine. There are technical and organizational reasons for that. When you're working with C++, you're almost guaranteed to need to deal with C as well, so jobs for "C/C++ developers" make perfect sense. There is also a certain level of expectation that future versions of both languages keep incompatibility between one another to a bare minimum. I'd happily apply for a "C/Rust" job as well.
- andai 6y agoThis is because the Windows filesystems (in backwards compatibility with DOS) are not case sensitive, so the compiler doesn't distinguish between .C and .c
- Someone 6y agoNowadays, they’re case-preserving, so the compiler _could_ distinguish the two. 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.
- karatinversion 6y agoI've had similar fun on macOS, where IIRC the project had both an API.h and an api.h file.
- Joker_vD 6y agoInterestingly, the blog post doesn't mention the actual problem that's the source of the MSVC behaviour: not all filesystems are case-sensitive. 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.
- DSMan195276 6y agoThat's actually an interesting one - for gcc at least `.S` indicates an assembly file that requires preprocessing via `cpp`, and `.s` does not. You could definitely wire it up such that a different extension indicates preprocessing (and there might be some others already), but the typical convention would run into this problem. Of course, you're not supposed to check in the preprocessed source, but you'd likely run into the problem at build time when it tries to create the preprocessed file with the same filename as the original, so it doesn't really solve the problem.
- cesarb 6y ago> but you'd likely run into the problem at build time when it tries to create the preprocessed file with the same filename as the original 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).
- DSMan195276 6y agoYeah that's a good point, I didn't really think about it too hard but usually you just go straight from the `.S` to the `.o` and more-or-less skip the intermediate.
- kalleboo 6y ago
- nanis 6y agoI've run into `.C` files a few times since the 90s. They were associated with projects managed by developers who were actively hostile to the notion that people might do development on Windows and they knew what they were doing.
- Joker_vD 6y agoOver the last 7 years I've seen many small or hobby projects on GitHub that started non-portable, and there would always be an issue/comment about "how do I compile it on my OS?". Now, it's completely anecdotal and recalled from memory, but the reactions of Windows-based developers to "doesn't compile on Linux" was generally "OK, I'll try to take a look", while the reaction of Linux-based developers to "doesn't compile on Windows" was generally "switch to Linux or try to compile with Cygwin but honestly, idgaf lol". 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.
- SAI_Peregrinus 6y agoWindows is expensive. Linux is free. Now that MS offers free trial Windows VM images for developers it's less of an issue, but traditionally it's been significantly cheaper for a Windows dev to set up a Linux system than for a Linux dev to set up a Windows system.
- jolmg 6y ago> Now, it's completely anecdotal and recalled from memory, but the reactions of Windows-based developers to "doesn't compile on Linux" was generally "OK, I'll try to take a look", 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.
- Semaphor 6y agoSemi-related: There is now a way to set a case-sensitive flag for NTFS directories `fsutil.exe file setCaseSensitiveInfo C:\folder enable` Here’s an article about it: https://www.howtogeek.com/354220/how-to-enable-case-sensitive-folders-on-windows-10/ https://www.howtogeek.com/354220/how-to-enable-case-sensitiv...
- jussij 6y agoI would suspect using that option would only open up a bunch of other unexpected issues, only because Windows programs have been written expecting that case insensitive file system. 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.
- Semaphor 6y agoDepends on the application I would think. If they do everything properly, they should let the file system handle it and not care themselves about case-sensitivity.
- jussij 6y agoThe problems start whenever a program asks the user for a file name and it then saves that raw users input. 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.
- 6y ago
- rm445 6y agoIt's mildly upsetting to me that the usual file extension for C++ isn't .c++, or for that matter .C++ Why shouldn't it be?
- SloopJon 6y agoProbably because "+" is a special character in most shells. You'd have to quote the filename every time you did anything with it. Edit: morning brain fart. Actually, I guess "+" is not all that special.
- Athas 6y ago`.cpp` is very common. I never understood the point of `.C`; even ignoring issues with case sensitivity, it is too easy to visually confuse with `.c`, and doesn't even have much of a mnemonic connection to the name C++.
- muststopmyths 6y agoAccording to wikipedia "+" is a reserved (prohibited) character in old/classic FAT file names https://en.wikipedia.org/wiki/Filename#Filename_extensions https://en.wikipedia.org/wiki/Filename#Filename_extensions 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.
- jmrm 6y agoI don't find any good reason to use .C instead of .cpp, .Cpp, .cxx, .Cxx, or similar. That two characters more of information helps compilers and other persons a lot.
- beached_whale 6y agoI had a fun time trying to figure out why a dependency project, my own, was not building via FetchProject in cmake. Macos by default, like windows is case preserving but insensitive too. My CMakeList.txt file was named CMakelist.txt and Linux Ext4 is case sensitive. Cmake really shouldnt care, or use all lowercase everywhere
- SAI_Peregrinus 6y agoIMO filesystems should treat different characters as different. Case-insensitivity at the storage level is always a mistake. It's occasionally fine for search or display, but it's a lossy operation. Sadly legacy compatibility has kept this choice on a number of filesystems.
- qalmakka 6y agoCase insensitive filesystems are a horrible idea, because you have to take encodings into account and the Turkey test, which means that either your normalization is broken or something will be equal under en_US but not tr_TR. Normalization should be done in the file manager or in a gui file picker, and not at the filesystem level.
- SAI_Peregrinus 6y agoExactly. But Windows and MacOS were made with the US-centric view that letters of different case are identical (they're not, thankfully even ASCII didn't make that mistake), and now we're stuck with it due to large amounts of legacy software relying on that assumption.
- beached_whale 6y agoI agree, but I think that the tooling should appreciate and handle the cases uniformly. On a case sensitive system, in the not found error handling, look for other names and warning that this might be the case. Ideally for the cmake tool, the filename should not have anything but lowercase letters too.
- qalmakka 6y agoI haven't seen a "big-C" file in years. Does any project that started after 1999 still use them? Anything I have ever read either uses .cpp, .cc, or more rarely .cxx.
- deleted 6y ago[deleted]