A lot of SO users, especially novice or inexperienced programmers who frequently ask questions, are genuinely confused about the differences between C and C++. As such, you frequently find questions that are posted with code that is specific (or should be specific) to one language or the other, but are tagged with both the C and C++ tags.

Now granted, the languages are not entirely dissimilar. C++ is even designed to be [mostly] backwards-compatible with C. But if you're writing C code in C++ and taking advantage of that backwards compatibility, then you're not really writing C++ code. And your question should be tagged accordingly.

This issue extends beyond the simplistic difference that "C++ is an object-oriented language". C is not a subset of C++, and C++ isn't simply "C with classes". That language doesn't exist. One simply does things differently in C++ than they would in C, and vice versa. If the tags don't take that into account, it becomes an unfortunate reality that many of the answers don't take that into account. One might argue that the actual differences between the two languages are somewhat "rare" in common usage, but a site like Stack Overflow is going to attract a lot of questions that are specifically about those weird, edge cases that a developer couldn't figure out on her own.

Most importantly, for questions and answers that involve (or quickly can evolve to) "best practices", the recommendations that one would make for C are almost always different from the recommendations for C++. Despite the two languages' syntactical commonalities, the idioms are in many cases so different as to be polar opposites. If syntax were the only concern, tagging questions C and C++ would make as much sense as the duo C++ and C#. But I bet there aren't very many questions with those two tags together (aside from those concerning interop, which obviously don't count...)

From my observation, the worst possible thing is that questions about one language or the other get hastily closed as duplicates of questions that are specifically about the other language. The issue is that the other question carries both tags, so it's natural to assume that it either covers both languages or is about one of those things that remains the same. I've even voted to do this myself and failed to notice the error until someone more careful than I posted a comment highlighting the difference. It's difficult to imagine how many times 5 people have hastily agreed to close a question before noticing the duplicate is actually about the other language, despite carrying both tags and superficially appearing to be a dup. And if C/C++ programmers can make that mistake, imagine how easy it is for smart programmers in other languages to make it.

Therefore, it seems that we should strongly consider disallowing a question from being tagged with both the C and C++ tags simultaneously. The relatively small and specific questions for which this would make sense would not be substantially negatively affected by having to choose one tag or the other. This wouldn't have to go into effect for past questions if that keeps down the amount of work required to implement it. The primary concern, it seems to me, is new questions. At a minimum, we should consider showing a warning to the asker when they add both C and C++ tags to a question.

To pre-empt comments that the community could always edit the tags to fix erroneous co-tagging, consider that it's not always obvious from the question which language the asker is hoping to discuss. That forces editors to make a lot of assumptions about the question being asked that may or may not be correct. It seems the goal of editing (even tags) should be to minimize the assumptions necessary, not increase them. If the asker is forced to choose the most appropriate tag, she may choose incorrectly, but it seems the chance is greatly reduced. If and when it becomes obvious that someone has chosen incorrectly, an edit easily solves the problem.


migrated from meta.stackexchange.com Apr 27 at 21:30


Should similar tags (like discussion and feature-request on meta) also be mutually exclusive? –  dalle Jan 10 '11 at 21:52
Hypocrite: You favor banning dual-tagged questions, but used "C/C++" in your question. –  Ben Voigt Apr 7 '11 at 3:52
@Ben: The implication wasn't that they're the same language. I'm lumping them together for the specific purposes of this question. I think that's clear from the context. "C/C++" modifies programmers, not the language itself. It would be no different than saying "C#/Fortran programmers". –  Cody Gray Apr 7 '11 at 6:38
I think you missed my point. It's absolutely correct to use "C/C++" in that way. But you provided your own counter-example to a post suggesting "decide whether you're talking about C or C++, it can't possibly be both", because clearly "C/C++" IS both. –  Ben Voigt Apr 7 '11 at 14:05
add comment

4 Answers

up vote 25 down vote accepted

A warning might be useful. Forbidding dual tagging, definitely not.

Consider: "How do I write a header file so that it can be #included by both C and C++ programs?"

Furthermore, I've seen people retagging questions from c++ to c because they feel no C++-specific features are being used, even when the code invokes different behavior on C vs C++ compilers. Classic example: "Error on line int* pi = malloc(sizeof (int));". This is a perfectly reasonable issue1 under C++, and retagging c destroys the meaning.

1 No, using malloc as a general purpose allocator in C++ isn't recommended. But C++ programs often use libraries written in C and may have to pass in buffers which will be deallocated using free(). new[] and free() are not compatible. To work with that library the C++ code will need to call the malloc() function, which is included in the C++ standard library. Questions about calling malloc() in C++ require the c++ tag. Ditto for questions about stdio and many others.

+1, Good example! –  Gabe Apr 7 '11 at 6:05
Agreed. Further reflection indicates that my proposal definitely went too far. I hadn't revisited the question again until being notified of your answer. I agree that a warning is definitely the better solution. And once such a warning system is implemented, it could be extensible for other potentially "unsavory" tag combinations (if the need were to later arise). –  Cody Gray Apr 7 '11 at 6:39
Note that I also wasn't proposing that others retag the question to C. I think that's almost always a mistake. That's why I was searching a way for the original asker to pick the most appropriate tag. –  Cody Gray Apr 7 '11 at 6:40
@Cody: Then exactly what did you mean by "But if you're writing C code in C++ and taking advantage of that backwards compatibility, then you're not really writing C++ code. And your question should be tagged accordingly."? Cause it sounds like you're saying such questions should be tagged c, and I'm telling you, if you using a C++ compiler, the question should be tagged c++, regardless of which functions and classes from the standard library are being used or not used. –  Ben Voigt Apr 7 '11 at 14:03
Ah, that's a fair point. Hrmm, it's been a while since I wrote the question. I apparently forgot some of the arguments I made... –  Cody Gray Apr 7 '11 at 14:05
Do we need a tag for C/C++ interoperability, and a tag for differences between the languages? –  dfeuer Jun 5 at 13:35
@dfeuer: Even if you add such a tag (which I think is not a bad idea), it wouldn't make the individual c and c++ tags inappropriate for those questions. –  Ben Voigt Jun 5 at 15:02
Actually, compiler specific behavior is compiler specific, and not standard behavior pointed out by the spec. I would only use the standard language tag for questions covered by the specification, otherwise I would opt for compiler specific tags. So be careful when writing "different compiler" or "different language". The example above is definitely not compiler related as your answer somehat implies that, misleadingly. That behavior is well-defined by the standard. –  Final Contest Jun 19 at 7:16
Based on your reply, it does not seem to be the case that I misunderstanding what you wrote. I am just pointing out we are discussing languages, not compilers as your example implies. In other words, it is slightly confusing what you wrote, and could be improved with focusing on the language rather than the compiler. –  Final Contest Jun 19 at 8:30
If it was, I would not bring it up, but it is up to you: if you do not want to improve your post, do not improve it. There is no point in arguing if you had already made your mind up. It is clear that this has nothing to do with the compilers, but the standard. Any mentioning of compilers is simply red-herring. –  Final Contest Jun 19 at 15:12
If you ask the OP what language they are using, someone will argue with them. Only the compiler is a clear test. That is why I talk about the compiler. –  Ben Voigt Jun 19 at 15:12
No! The malloc difference is best-proven by quoting standard material. –  Final Contest Jun 19 at 15:14
It would not be an "improvement" to return to hand-waving about what language the question is in, which invites the retagging based on what functions from the library are used. –  Ben Voigt Jun 19 at 15:14
@FinalContest: And how do you know what standard to refer to? How do you know what language a question is concerned with? You look at the compiler. –  Ben Voigt Jun 19 at 15:15
No, gcc can compile both, so that will bring you nothing, as well as cl.exe, or I could even mention clang here. What you need to do is to ask the OP about the language. We are not discussing compiler tags here and their specific implementations. –  Final Contest Jun 19 at 15:19
show 2 more comments

This wouldn't solve anything.

There are lots of questions that were originally tagged [c] where the OP was clearly using [c++] and there are lots of questions that were originally tagged [c++] and when a C++ solution was given, the OP said "oh, no, I'm using C."

Forbidding a question from being tagged both [c] and [c++] is just silly. There are plenty of questions that can be asked about both languages (for what it's worth, one of my questions is correctly tagged both [c] and [c++]).

Well... maybe encourage people who don't know any better to tag them with both. That way an expert who understands the question can come along and retag them. –  Nathan Osman Jan 10 '11 at 17:44
This answer is incomplete (and as a consequence, overly negative), because it doesn't address the proposed alternative in the question, which is "At a minimum, we should consider showing a warning to the asker when they add both C and C++ tags to a question" I agree with your reasons for not forbidding dual tagging, but I think a warning would address a lot of cases (and they appear to be very frequent) where the questioner uses both tags due to inexperience rather than legitimate need (albeit Michael's answer does state some concerns with having a warning). –  JBentley May 7 '13 at 22:11
add comment

This seems like a really specific use-case; the engine really needs special functionality added just to detect people using and on the same question? If the poster really doesn't know what they're doing, this won't fix anything; they'll add both tags to their question, see the error message (if it's a warning I guarantee it won't even slow them down, take a look at the "this post is subjective and will likely be closed" warning), and delete whichever tag they typed last, so now instead of a bunch of posts with both tags that are easy to find, there will be a bunch with one tag that should have the other

It's definitely a specific use case, but that seems like something that afflicts tagging in general. You're probably right about people ignoring warnings, though. My concern isn't that the doubly-tagged questions are difficult to find, it's that they're confusing to everyone and perpetuate the misunderstanding that the languages are the same. –  Cody Gray Jan 10 '11 at 15:30
It would be nice if tags could be marked mutually exclusive with specific other tags. I could probably come up with a few others, too, particularly ones related to specific versions of software. –  Powerlord Jan 10 '11 at 18:06
add comment

Unfortunately, there are some of us who have to do C and C++ interop, eg. when linking with OS and 3rd-party vendors who provide only C libs. I have ifdef C/cplusplus all over my projects and would not support a blanket ban on using both tags.

I'm having trouble discerning how your proposed resolution to this, or even your rationale, is different from mine –  Ben Voigt May 7 at 22:47
@BenVoigt: what Martin is writing, it would be harmful banning tagging both because it would not help certain people. It seems reasonable to me. –  Final Contest Jun 19 at 8:33
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .