Is there a better way to do C style error handling?

前端 未结 10 1841
时光说笑
时光说笑 2021-02-20 06:43

I\'m trying to learn C by writing a simple parser / compiler. So far its been a very enlightening experience, however coming from a strong background in C# I\'m having some pro

10条回答
  •  抹茶落季
    2021-02-20 07:35

    You're probably not going to like to hear this, but the C way to do exceptions is via the goto statement. This is one of the reasons it is in the language.

    The other reason is that goto is the natural expression of the implementation of a state machine. What common programming task is best represented by a state machine? A lexical analyzer. Look at the output from lex sometime. Gotos.

    So it sounds to me like now is the time for you to get chummy with that parriah of language syntax elements, the goto.

提交回复
热议问题