Is it possible to store the address of a label in a variable and use goto to jump to it?

前端 未结 14 1612
执念已碎
执念已碎 2020-12-04 09:35

I know everyone hates gotos. In my code, for reasons I have considered and am comfortable with, they provide an effective solution (ie I\'m not looking for \"don\'t do that\

14条回答
  •  我在风中等你
    2020-12-04 10:29

    The C and C++ standards do not support this feature. However, the GNU Compiler Collection (GCC) includes a non-standard extension for doing this as described in this article. Essentially, they have added a special operator "&&" that reports the address of the label as type "void*". See the article for details.

    P.S. In other words, just use "&&" instead of "&" in your example, and it will work on GCC.
    P.P.S. I know you don't want me to say it, but I'll say it anyway,... DON'T DO THAT!!!

提交回复
热议问题