-4

Note: This suggestion comes out of some discussion in the comment thread on this question.

Many times in recent months, I have noticed questions about C++ code which are tagged ambiguously as C/C++ questions, and make no mention of compiler or standard -- then an argument ensues among the various folks who provide answers to such questions about how best to proceed.

My experience has been that, oftentimes, the code is obviously not C for reason of including C++ headers or something, and so the C tag can be ignored. Or, it seems like the question really has nothing to do with C++ and so the C++ tag is ignored. Occasionally it happens that people decide to retag it just as C / C++ (example) and there are earlier meta threads about that issue.

This thread is about a different but related issue -- when a question is tagged only as C++, and there is no mention of a compiler or standard, how should we answer?


My experience / impression had been that usually, you assume at least C++98 standard, maybe C++11 -- if it makes a difference you can describe the difference in the answer. For instance that was the basis I gave for this answer which people seemed to like. Note that, the question is extremely difficult if not impossible to answer if you don't assume some standard -- OP asks whether behavior in some situation is defined or not.

In the linked question (from today, here's the link again), OP posts some code which variously could be C or C++, and uses a gcc-specific extension function. Then he asks if it is "legitimate".

Argument ensues about whether "legitimate" means standards-compliant, and if not, what else it could mean / what could be the basis of answering the question.

In this case, the question got retagged to add the gcc tag and then answered on that basis.

From the exchange in the comments, my impression now is that the [c++] tag is actually extremely broad, much broader than I had thought. Especially, from the up-voted answer in this meta-question

If someone tags a question as C++, then they are intending to write and compile C++ code. Even if the code is horrible, and they have likely compiled it using a copy of UnicornsC++Compiler that does not follow the standard of C++, they still want an answer that makes it work in C++.

If the C++ tag is meant to encompass also these questions that aren't about "standard" C++, then a lot of questions become ambiguous / hard to answer, and a lot of questions end up accumulating a lot of comment wars between answerers about what is an acceptable basis for an answer.

In many cases, if the question is easy / basic, it doesn't really matter what standard or compiler they target.

But in other cases, if you can't assume some kind of standards-conforming compiler is being used, or, you might be supposed to answer assuming any compiler, this makes what would be an easy question very broad and requires expertise that many fewer people have -- most people don't necessarily have a lot of experience with more than a few compilers, and there are a lot out there.

In the comment thread on this most recent question, @Karoly Horvath writes:

@ChrisBeck: No idea. I just use common sense. Novice users have no idea about these issues, and should be informed gently. – Karoly Horvath 51 mins ago

I think that is right, it usually isn't that hard to figure out what to do. However, what I'm suggesting is that we should try harder to make people not just use the [c++] tag, but also to specify one or several standard tags, or specify a compiler tag, and aggressively retag questions as it becomes clear.

  1. It makes it alot easier for people who are browsing questions / looking for useful info if the standard / compiler being discussed is clearly tagged and they don't themselves have to do the common-sense deduction while browsing around. This makes SO a more useful resource for everyone.
  2. It avoids these common and unsightly threads of comments where OP may mostly not participate and a bunch of C++ gurus go back and forth about what is a reasonable basis for answering the question.

Further, what I think we should do is edit the tag wiki for [c++] so that it clarifies the meaning of the tag. Currently it reads:

C++ is a general-purpose programming language based on C. Use this tag for questions about code (to be) compiled with a C++ compiler.

I think it should includes at the end a sentence along the lines:

Questions tagged only as [c++] are not assumed to be about code conforming to any particular standard -- for this reason, many questions are too broad to answer unless you also specify one or several standards / compilers. Please consider adding tags like [c++11], [gcc], [msvc], etc.

Alternatively, I guess we could decide that SO is more useful as a resource if we assume they are using some standard-conforming compiler unless they specifically say otherwise -- don't consider possibility of UnicornC++ unless they mention it. But regardless I think it would be better if we decide this on meta and then say it clearly in the tag wiki entry. For most other programming language tags on SO I guess there isn't this issue of "what if they are using a non-conforming implementation", it's always assumed that javascript answers follow some ECMAScript standard, etc. So if the C++ tag works differently it is probably worth documenting that somewhere.

15
  • 2
    Why not widen that to C or any other language with a commonly accepted norm or even an official/international standard. I don't think this subject is language-specific. Jan 19, 2016 at 23:31
  • (Note that OP re-tagged the question C-only after some clarification in comments) Jan 19, 2016 at 23:35
  • I guess it could be widened to include C but there aren't so many competing implementations of other languages that differ greatly afaict -- this seems to be more of an issue for C++ imo
    – Chris Beck
    Jan 20, 2016 at 1:05
  • See the question which caused the discussion. That very well was about both. And there are other C questions I had the same fight.6 But I like that name "UnicornC++". Wonder if that is from the same company as "WolpertingerC" or "YetiFortran" ;-)? But agreed, I see not much use beyond those two languages. Jan 20, 2016 at 1:18
  • As this is my first session on meta: Am I supposed to provide an answer or is that more like a discussion? Jan 20, 2016 at 1:20
  • @Olaf: I guess I don't really know, in the past when I made a suggestion like this, either it gets upvoted and later someone authoritative signs off / does something, or it gets downvoted, and someone authoritative makes an answer explaining why its bad, which other people upvote. I guess if you want to suggest a resolution that people can approve / disapprove you could make an answer?
    – Chris Beck
    Jan 20, 2016 at 1:27
  • @Olaf: Mainly I made this thread because I don't think I should just push a change to the C++ tag wiki without a discussion first -- there's a lot of people who use the tag I guess. But maybe that's how this should be resolved? Not sure
    – Chris Beck
    Jan 20, 2016 at 1:31
  • 1
    Some people in the [c] and [c++] tag are hopelessly hardass about it. In practice, many C programmers know C++ and many C++ programmers know C. Questioners always aim for the largest audience. If you can't tell the difference then you should not be answering questions with those tags. Jan 20, 2016 at 9:15
  • 2
    @HansPassant: Might you have missed the point? This is not really about retagging C or C++ questions (see the text, there is already a meta for that). This is about whether to stick to the standard or not. My point currently is that this is just about C++, while it is one of the rare cases this applies to C, too. Both being different languages is well-accepted and not part of this meta anyway. Btw., If someone is willing to answer for both languages, he will/should monitor both tags. Tagging a question both just to get the "larger audience" is against rules. Jan 20, 2016 at 10:24
  • 2
    "Do not use this tag"
    – user1228
    Jan 20, 2016 at 14:09
  • @HansPassant, the proposal does not have to do with people who can't tell the difference between C and C++, it's about providing a cue to readers and answerers what the precise context of the question is, and a cue to questioners that they may get a better answer if they are more precise. Or how to show that they expect a very general answer.
    – Chris Beck
    Jan 20, 2016 at 22:33
  • That cue should always be in the question. The [tags] are there to find people that could understand the question. You will never be able to stop questioners from trying to find people to help them. You can delete the tag you don't like, nobody will stop you. It is however an activity that gets old in a hurry. You can berate the OP for using the tag in a comment, me having to read them gets old in a hurry. It does not stop them, resistance is futile. We can all get along, C and C++ are not cats and dogs. Jan 20, 2016 at 23:19
  • @HansPassant: You seem intent on ignoring me when you keep rehashing about C and C++. That is not the topic here -- the topic as I wrote it is C++98 vs C++11 vs gcc C++ vs Unicorn C++. I understand you get tired of retagging things -- another activity that gets old in a hurry is arguing with people about what the real topic of a C++ question is, and having to read the same exchanges over and over again. Can we agree on this? What I'm hoping to come out of this, at minimum, is agreement about what I asked in bold... then I can refer to this meta thread later. A tag edit/update would be gravy.
    – Chris Beck
    Jan 20, 2016 at 23:46
  • 1
    Odd, I got the impression that you are ignoring me. That's fine, I'm not trying to change the way it works, I'm just telling you how it works. Helping you to berate a questioner with a meta link, no, that is very boring as well. Jan 21, 2016 at 0:17
  • You aren't being ignored here, or "just telling me how it works", you've actually been off-topic the whole time, as @Olaf tried to point out and then as I did. I would like to have a discussion and get a clear answer from those who visit meta to a pretty reasonable, and specific, question. You may disagree with my take on the answer, but to ascribe some malicious intent to my asking a question on meta is rather bizarre in my opinion. Obviously some of us who answer questions in this tag are interested in the answer -- metalink is for them, not to "berate a questioner".
    – Chris Beck
    Jan 21, 2016 at 0:38

1 Answer 1

2

Not sure if that counts as a complete answer - please drop a comment if you think it doesn't. Also note that I'm more a C man than C++, so I might provide more details to the former language.

First of all, I think the question applies to C as well. Having said that, the following is about both unless otherwise stated. It does not apply to otuer languages unless explicitly stated.

Basically the question can be reduced to "What is C (resp. C++)?". A bit deeper, it resolves to "What is correct syntax, grammar and semantics?"

Many questions here arise from a program not behaving as expected. Many of them arise from violating constraints of the language definition. While there are many languages which only have an "informal" definition, for C and C++ exist international standard. Different from languages like e.g. Pascal (for which also an ISO standard exists), the C and C++ standards are very well established and accepted. Most compilers nowadays support at least some old version of the corresponding standard, many of them also a "stable" version, i.e. one where the basic features have settled and new versions mostly add new features, but do not change older ones. The latter is a bit more true for C than for C++.

For C, the stable standard would be C99 (there were some slight semantical changes and important additions to C90). While MSVC does not support C99 very well, MS has announced to support C11 (some day). Other major compiler like gcc support C99 completely (library issues excluded, that is not a matter of gcc, but glibc) and most features of C11 since some years (the recent version have quite complete support now).

For C++ it could be C++98, but from my observations, it might be C++11 now (which introduced important new concepts). AFAIK, most major C++ compilers - including MSVC++ support the newer standard already. Support of C++14 is on-going, but that is more an update release anyway.

So much for the desktop/server-field. For the embedded field, at least C++98 language support is acceptable for features relevant for bare-metal embedded systems (not all features are really useful there). C99 support is still growing. All for commercial compilers. gcc, which has a growing market-share (mostly due to growing use of 32 bit MCUs) profits from the large-iron-market and supports current standards where applicable.

To conclude: Currently almost all C compilers support some realtively recent version of the standard or - for the given usage - acceptable subset of it.


With that in mind, I think a question being tagged only with the language-tag, but no compiler, standard-version and not incuding information (direct or indirect) in the text itself, should be treated as heading for standard-compliance. So, the question "is this code correct" should be answered according to the information given. There should not be made assumptions about deviations.

Things become more complicated if a question includes obvious extensions of a compiler, but does not state that compiler. It also asked if that code was legit, but without stating the compiler. For such questions, a comment should be used to clarify which compiler/standard version is used and if OP is aware these are extensions. If OP does not answer even after another request, the question is incomplete and should be closed. Alternatively, if it is a minor issue, an answer should include notes about the extensions and constraints. Which reaction is correct depends on the question and possibly comments.

Basically, without a common basis to qualify code as correct or not, any answer would be useless. Things like undefined behaviour only make sense if context for the "undefined" is known. In other words: Where is the behaviour not defined? ("There are no ice-bears" only makes sense if context is given: "in antarctica" - It is wrong in a more global sense; even in Africa there are likely some - in zoos).

It should be noted there is only one valid standard: the current one (C++14 resp. C11). It is established procedure to withdraw the older version of a standard when a new version is release. So - strictly speaking - e.g. standard C is only C11. But - as I mentioned - C99 already was quite stable and C11 did not add semantics significantly, but mostly added new fatures, there normally is no problem with C99 code. The same might apply to C++98 vs. C++14.


About updating the descriptions and info-pages: I strongly support updating them. But I primarily tend to state very clear ISO standards exist and they are well-established. The pop-ups should already contain this information, the info-page should provide a reference to the standard document - if possible - at a (more) prominent position early in the text (for C, that is somewhere hidden at the end).

You must log in to answer this question.

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