6

Example

What it looks like

last should not be highlighted as it is not a keyword in C++. Not sure why the tag causes it to be highlighted as that's a compiler, not a language.

Steps to reproduce:

  1. Edit
  2. Remove the tag
  3. Make a minor edit in the textbox to force refresh
1
  • 1
    Could it be by chance, that gcc is meant as a synonym for c? Try tagging with g++. Commented Jul 27, 2016 at 15:53

1 Answer 1

14

I don't think that is a bug. From What is syntax highlighting and how does it work?

If there's more than one tag that has syntax highlighting, it uses a default and lets Prettify infer what's the best language to use.

That question has multiple tags with a language hint on it (scroll to the end of the wiki):

has no language hint.

This means Prettify falls back to the Default which is all possible keywords of major languages smashed together. I explained more in depth how that works here.

If you want proper highlighting add the explicit prettifier to use <!-- language: lang-cpp --> or <!-- language: lang-c --> above the relevant code blocks.

Or even better: Don't mix C and C++, ever.

10
  • Can you be specific about which tags have the language hint? I don't see anything on the list that's relevant except cpp. Commented Jul 27, 2016 at 16:00
  • 1
    You're right that it does use the default highlighter, as confirmed by Element Inspector. But I still think it's a bug if GCC is considered a valid language for the highlighter. Commented Jul 27, 2016 at 16:06
  • 4
    It is not a bug, the highlighter doesn't know which language to use. If you be explicit all works fine.
    – rene
    Commented Jul 27, 2016 at 16:08
  • 1
    OK looks like πάντα ῥεῖ was on the money. gcc has a language hint after all: "Code Language (used for syntax highlighting): lang-c". Still, I find that pretty surprising and a "bug" on SE's part. Commented Jul 27, 2016 at 16:10
  • I'm not a C/C++ guy but if you think gcc shouldn't use lang-c as its prettifier you can open a support question for that. Make sure to check the current questions tagged gcc to verify that otherwise a bunch of other users get confused and start raising bugs.
    – rene
    Commented Jul 27, 2016 at 16:14
  • 3
    It makes sense for gcc to use lang-c. g++ should use lang-cpp. Obviously there's nothing wrong with tagging a C++ question with gcc, though, so this just proves that syntax highlighting is hard. Perhaps the best thing to do would be to remove the syntax highlighting hint from gcc and g++ since those would never be correctly used without either c or c++.
    – Cody Gray Mod
    Commented Jul 27, 2016 at 16:29
  • @CodyGray I think removing the highlighting would be best. I don't see how you could use gcc or g++ without a language tag when posting a code block. Commented Jul 27, 2016 at 16:42
  • @CodyGray I doubt that rule will be applicable across all tags and all type of questions. Where you have a choice but no knowledge about the context by applying a single lang-* you could be 100% wrong. By applying the lang-default, you can have luck and nobody notices ...
    – rene
    Commented Jul 27, 2016 at 16:44
  • I didn't say to apply it to all tags...
    – Cody Gray Mod
    Commented Jul 27, 2016 at 17:26
  • 1
    @CodyGray Definitely agree that gcc should not have a language highlight. It's tag wiki says it refers to the Gnu Compiler Collection, not the old acronym of the Gnu C Compiler. Therefore it is just as justified to use it for C++, Java, Fortran, Ada or any other language GCC supports. Thus it should not have any associated language.
    – Vality
    Commented Jul 27, 2016 at 20:00

You must log in to answer this question.

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